Skip to content

Commit b1651ba

Browse files
committed
Added socket disconnection if commands are rejected due to AOF/RDB load.
SELECT commands are issued only on initial socket connection. If a user issues a command during an AOF/RDB load, the socket connection will be successfully opened, but the SELECT command will be lost. If subsequent commands are sent after the AOF/RDB load is completed, the SELECT command will not be retried (due to the open socket), and those commands will go to the wrong DB. This behavior appears to be present in hiredis as well as redis-py. Fixing it here by special casing the AOF/RDB load message and closing the socket connection before raising ResponseError.
1 parent 2eb518a commit b1651ba

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

redis/connection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ def read_response(self, command_name, catch_errors):
9797
if byte == '-':
9898
if response.startswith('ERR '):
9999
response = response[4:]
100+
if response.startswith('LOADING '):
101+
# If we're loading the dataset into memory, kill the socket
102+
# so we re-initialize (and re-SELECT) next time.
103+
self.disconnect()
104+
response = response[8:]
100105
raise ResponseError(response)
101106
# single value
102107
elif byte == '+':

0 commit comments

Comments
 (0)