Repository navigation
zulip: Retry requests over stale keep-alive connections. - #947
Open
harshvardhan178251 wants to merge 1 commit into
Open
harshvardhan178251 wants to merge 1 commit into
harshvardhan178251 wants to merge 1 commit into
Conversation
harshvardhan178251
force-pushed
the
fix-761-stale-connection
branch
from
November 14, 2026 14:44
64cdbe2 to
75a80e9
Compare
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.
Fixes: #761
Some networks silently kill idle TCP connections (e.g. GitHub Actions' ~270s idle timeout). The
requestssession Zulip uses pools keep-alive connections, so the next request over such a stale pooled connection fails with a connection error even though the server is healthy; that is what was happening in the referenced oneclick deployments. urllib3's default retry policy does not retry non-idempotent methods on connection errors, so the error propagated to callers.This PR mounts an HTTPAdapter with a urllib3 Retry (3 attempts, 0.5s backoff, connection/read errors only, HTTP statuses untouched) on
http://andhttps://inClient.ensure_session(). The retry covers the stale-connection class of connection errors; status-code handling and the existingerror_retry/has_connectedlogic indo_api_queryare unchanged.allowed_methods=None(retrying POST included) because over a stale pooled connection the request is never delivered.One design decision worth flagging for review: if a request reaches the server but the response is lost, a retried POST could be delivered twice (e.g. a duplicate message). This is the same trade-off the issue describes for "a transparent retry for this class of connection error", and the failure mode is rare and self-limiting; alternative would be to scope retries to idempotent methods only, which would not fix the common case (Zulip API calls are mostly POSTs). Happy to narrow the retry policy if maintainers prefer.
How did you test this PR?
zulip/tests/test_session_retries.pyasserts the mounted adapter's retry configuration for both schemes.zulippackage passes locally (13 passed).ruff checkandmypyclean. (zulint/tools/lintrequires Unix executables and was run via ruff/mypy directly;zulip_bots/has 41 pre-existing failures due to missing optional third-party bot dependencies, unrelated to this change.)requirements.txt(e.g.#egg=zulint==1.0.0) are rejected by current pip; installed with equivalentrequirementslocally without modifying the repo.Self-review checklist
Communicate decisions, questions, and potential concerns.
Individual commits are ready for review (see commit discipline).