Set client name in HELLO
handshake during connection initialization
#3294
+27
−1
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.
Context
Connection initialization consists of 3 independent operations, executed sequentially:
HELLO
handshake (ref: https://github.com/redis/go-redis/blob/v9.7.1/redis.go#L313)The
HELLO
command supports an optional property,SETNAME
, that allows the client name to be set on the connection at handshake-time, thus making any subsequentCLIENT SETNAME
unnecesary.https://redis.io/docs/latest/commands/hello/
Problem statement
We are running go-redis against a proprietary RESP protocol-compliant server that correctly recognizes and manipulates client names on connections.
The problem with the sequence of 3 operations above is that the client name is not known to the server until completion of step 2. This means that, the client identity is unknown at completion of step 1, and unknown at the start of step 2.
This has caused RESP handshakes to be flagged as coming from unknown clients.
Proposal
Since the
HELLO
command supports supplying the client name inline, simply pass the client-specified name in theHELLO
request. This should be supported by any RESP3-compliant servers. This patch is a noop if the client name field is empty.This does not remove
CLIENT SETNAME
from the subsequent pipeline; this is needed for backwards compatibility for RESP2 servers.This patch solves the problem statement described above because the client identity on the connection will be known at the time
HELLO
completes (assuming a RESP3 client). This allows all subsequent commands (namely, steps 2 and 3 above) to be correctly associated with a client identity.