Conversation
UnixDomainSocketConnection._connect() ended with an extra 'await self.on_connect()', while AbstractConnection.connect() also runs the handshake (on_connect, or the caller's valkey_connect_func) right after _connect() returns. Every async UDS connection therefore ran the default handshake twice: - HELLO/AUTH/CLIENT SETNAME/CLIENT SETINFO/SELECT were all sent twice per connection (with AUTH credentials that is double the credential traffic and double the round trips), and twice again on every reconnect; - when the caller passes valkey_connect_func, which is meant to replace the default handshake entirely (and does so on TCP), the default handshake still ran first on UDS - the same argument behaved differently on the two transports. Drop the on_connect() call from _connect() so it only opens the socket, leaving the handshake to connect() like the TCP and SSL paths. Repro on master (f3a73ec), fake AF_UNIX RESP server counting handshake commands: TCP: 2 handshake commands UDS: 4 handshake commands <- doubled TCP+custom valkey_connect_func: 1 UDS+custom valkey_connect_func: 3 <- default handshake leaked in Signed-off-by: 金豆 <jindou@jindoudeMacBook-Air.local>
simpleqt
requested review from
ahmedsobeh,
bogdanp05,
mkmkme and
smeso
as code owners
September 24, 2026 16:58
This branch has not been deployed
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.
Problem
valkey/asyncio/connection.py'sUnixDomainSocketConnection._connect()ends with its ownawait self.on_connect(), butAbstractConnection.connect()also runs the handshake (on_connect, or the caller'svalkey_connect_func) right after_connect()returns:Every asyncio UDS connection therefore runs the default handshake twice (verified on master
f3a73ecagainst a fake AF_UNIX RESP server that records commands):Consequences:
password/username, AUTH credentials are sent twice per connection (and per reconnect), doubling credential traffic and round trips;valkey_connect_func, which on TCP replaces the default handshake entirely, cannot do so on UDS — the default handshake still runs first:Changes
_connect()now only opens the socket; the handshake is left toconnect(), matching the TCP and SSL paths.Testing
Two server-free tests in
tests/test_asyncio/test_connection.pyspin up a minimal AF_UNIX RESP server and count the handshake commands:valkey_connect_func) — red(flake8 / black --target-version py37 / isort clean on the touched files)