Skip to content

Commit 631c053

Browse files
petyaslavovaCopilot
andcommitted
Fixing error handling of connection buffer purging of closed connecton. Enabling troubleshooting logging for maint notifications e2e tests. (#3971)
* Fixing error handling of connection buffer purging of closed connection. Enabling troubleshooting logging for maint notifications e2e tests. * Fix race condition in RESP3 parser buffer purge (#3972) * Initial plan * Combine None check with try-except for buffer.purge() to handle race condition Co-authored-by: petyaslavova <194077574+petyaslavova@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: petyaslavova <194077574+petyaslavova@users.noreply.github.com> --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: petyaslavova <194077574+petyaslavova@users.noreply.github.com>
1 parent fc2e574 commit 631c053

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

redis/_parsers/resp3.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,23 @@ def handle_pubsub_push_response(self, response):
2929
return response
3030

3131
def read_response(self, disable_decoding=False, push_request=False):
32-
pos = self._buffer.get_pos() if self._buffer else None
32+
pos = self._buffer.get_pos() if self._buffer is not None else None
3333
try:
3434
result = self._read_response(
3535
disable_decoding=disable_decoding, push_request=push_request
3636
)
3737
except BaseException:
38-
if self._buffer:
38+
if self._buffer is not None:
3939
self._buffer.rewind(pos)
4040
raise
4141
else:
42-
self._buffer.purge()
42+
if self._buffer is not None:
43+
try:
44+
self._buffer.purge()
45+
except AttributeError:
46+
# Buffer may have been set to None by another thread after
47+
# the check above; result is still valid so we don't raise
48+
pass
4349
return result
4450

4551
def _read_response(self, disable_decoding=False, push_request=False):

redis/cluster.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,8 +1573,13 @@ def _execute_command(self, target_node, *args, **kwargs):
15731573
e.connection = target_node
15741574
raise
15751575
except (ConnectionError, TimeoutError) as e:
1576-
# if we have a connection, use it, otherwise use the target node
1577-
# object which contains the host and port info
1576+
if is_debug_log_enabled():
1577+
socket_address = self._extracts_socket_address(connection)
1578+
args_log_str = truncate_text(" ".join(map(safe_str, args)))
1579+
logger.debug(
1580+
f"{type(e).__name__} received for command {args_log_str}, on node {target_node.name}, "
1581+
f"and connection: {connection} using local socket address: {socket_address}, error: {e}"
1582+
)
15781583
# this is used to report the metrics based on host and port info
15791584
e.connection = connection if connection else target_node
15801585

tests/test_scenario/test_maint_notifications.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
datefmt="%Y-%m-%d %H:%M:%S:%f",
4646
)
4747

48+
# Set DEBUG level for specific redis-py loggers
49+
logging.getLogger("redis.maint_notifications").setLevel(logging.DEBUG)
50+
logging.getLogger("redis.cluster").setLevel(logging.DEBUG)
51+
4852
BIND_TIMEOUT = 60
4953
MIGRATE_TIMEOUT = 60
5054
FAILOVER_TIMEOUT = 15

0 commit comments

Comments
 (0)