Conversation
ping('') was sent as a bare PING because the guard used truthiness: '' is falsy, so the message was never pushed onto the wire and the server answered PONG instead of an empty string.
Compare against undefined instead, the same way XREAD and SINTERCARD already do.
Contributor
Author
|
@nkaradzhov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3463
ping('')went out as a barePING. The guard wasif (message), and''is falsy, so the message was never pushed onto the wire and the server answeredPONGinstead of"".Change
parseCommand(parser: CommandParser, message?: RedisArgument) { parser.push('PING'); - if (message) { + if (message !== undefined) { parser.push(message); } },An empty message is not an omitted message -
''is a validRedisArgumentand Redis acceptsPING '', which is why the rawsendCommand(['PING', ''])path always worked. The siblingECHOnever had this guard, andXREAD/SINTERCARDalready compare againstundefinedfor the same reason.Tests
packages/client/lib/commands/PING.spec.ts:parseArgs(PING, '')now asserts['PING', ''].pingintegration test additionally asserts thatawait client.ping('')returns''. It runs on both the server and cluster topologies throughtestUtils.testAll.Verification
npm run buildnpx mocha -r tsx './lib/RESP/**/*.spec.ts'- 133 passingnpm test -w @redis/client- 3079 passing, 4 pending, 2 failing; both failures areSocket socketTimeouttimeouts insocket.spec.ts, unrelated to this change (details below)npm run lint- cleanThe 2 failing tests
Both are mocha 2000ms timeouts in
Socket › socketTimeout:They are load-dependent and not caused by this change. The full suite was run twice - once with this change and once on a clean
origin/master- and the same two tests fail identically in both:origin/masterSocket socketTimeoutx2)The only difference is the
+1from the newwith an empty messageunit test. Runningsocket.spec.tson its own passes on both trees, so they only time out under the load of the full parallel suite. This change touchesPING.tsonly and nothing on the socket path.Checklist
npm testpass with this change (including linting)?No documentation change:
ping(message?: RedisArgument)is unchanged, and the fix makes the implementation match what the signature already promised.Note
Low Risk
Narrow client command-encoding fix with added tests; no auth, security, or data-path changes.
Overview
Fixes
ping('')so it sendsPING ''and returns an empty string instead of behaving like a barePING(PONG).The
PINGcommand parser now treats an empty string as an explicit message by checkingmessage !== undefinedrather than truthiness, so''is pushed on the wire while omitting the argument still sends onlyPING.Tests cover
parseArgsfor''and integrationclient.ping('')on open server and cluster setups.Reviewed by Cursor Bugbot for commit 7741511. Bugbot is set up for automated code reviews on this repo. Configure here.