Skip to content

Fixing pubsub's listen method to be blocking.#4119

Open
petyaslavova wants to merge 2 commits into
masterfrom
ps_listen_should_blocking
Open

Fixing pubsub's listen method to be blocking.#4119
petyaslavova wants to merge 2 commits into
masterfrom
ps_listen_should_blocking

Conversation

@petyaslavova

@petyaslavova petyaslavova commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Fix Pub/Sub blocking reads so listen(), get_message(timeout=None), and parse_response(block=True) wait indefinitely for messages even when the client is configured with a finite socket_timeout.

The sync implementation now passes a per-read timeout=None for blocking Pub/Sub reads so the socket layer blocks until a message arrives. The async implementation uses math.inf as an internal per-read “block indefinitely” signal, preserving the existing public Connection.read_response(timeout=None) behavior where explicit None falls back to socket_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 direct parse_response(block=True) blocking past socket_timeout, plus async coverage that verifies blocking reads do not mutate socket_timeout or 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), and parse_response(block=True) keep waiting for messages when the client has a finite socket_timeout, instead of raising TimeoutError once that limit elapses.

Sync: blocking Pub/Sub reads now pass timeout=None into read_response, so the socket blocks until data arrives without applying socket_timeout for that read.

Async: the same blocking paths pass math.inf into Connection.read_response, which treats positive infinity as “no per-read timeout” while leaving the public rule that explicit timeout=None still falls back to socket_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 past socket_timeout and (async only) that socket_timeout is 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.

@jit-ci

jit-ci Bot commented Jun 12, 2026

Copy link
Copy Markdown

🛡️ Jit Security Scan Results

CRITICAL HIGH MEDIUM

✅ No security findings were detected in this PR


Security scan by Jit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pubsub.listen() times out if no messages received in 5s

1 participant