Fixing pubsub's listen method to be blocking.#4119
Open
petyaslavova wants to merge 2 commits into
Open
Conversation
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
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.
Fix Pub/Sub blocking reads so
listen(),get_message(timeout=None), andparse_response(block=True)wait indefinitely for messages even when the client is configured with a finitesocket_timeout.The sync implementation now passes a per-read
timeout=Nonefor blocking Pub/Sub reads so the socket layer blocks until a message arrives. The async implementation usesmath.infas an internal per-read “block indefinitely” signal, preserving the existing publicConnection.read_response(timeout=None)behavior where explicitNonefalls back tosocket_timeout.This avoids mutating connection-wide timeout state while a blocking Pub/Sub read is in progress, so reconnect, AUTH, HELLO, and resubscribe paths continue to honor the configured socket timeout. It also keeps timeout-limited
get_message(timeout=X)behavior unchanged.Added sync and async regression coverage for
listen(),get_message(timeout=None), and directparse_response(block=True)blocking pastsocket_timeout, plus async coverage that verifies blocking reads do not mutatesocket_timeoutor affect later timed reads.Fixes #4098
Note
Medium Risk
Touches core connection read timeout semantics for Pub/Sub on sync and async paths; behavior change is scoped to blocking reads but is on a hot I/O path with documented future API cleanup.
Overview
Fixes Pub/Sub blocking reads so
listen(),get_message(timeout=None), andparse_response(block=True)keep waiting for messages when the client has a finitesocket_timeout, instead of raisingTimeoutErroronce that limit elapses.Sync: blocking Pub/Sub reads now pass
timeout=Noneintoread_response, so the socket blocks until data arrives without applyingsocket_timeoutfor that read.Async: the same blocking paths pass
math.infintoConnection.read_response, which treats positive infinity as “no per-read timeout” while leaving the public rule that explicittimeout=Nonestill falls back tosocket_timeout. Reconnect, AUTH, HELLO, and resubscribe inside the retry layer are unchanged because they do not use that signal.Timed
get_message(timeout=X)behavior is unchanged. New sync and async regression tests cover blocking pastsocket_timeoutand (async only) thatsocket_timeoutis not mutated and later timed reads still honor it.Reviewed by Cursor Bugbot for commit 800a03f. Bugbot is set up for automated code reviews on this repo. Configure here.