fix: prevent intermittent connection resets in internal service client (#4971) - #5698
Open
krxshes wants to merge 3 commits into
Open
fix: prevent intermittent connection resets in internal service client (#4971) #5698krxshes wants to merge 3 commits into
krxshes wants to merge 3 commits into
Conversation
Two related issues in SessionManager/_call (_bentoml_impl/client/proxy2.py): 1. The tcp-scheme branch of _make_client() left connector=None, so aiohttp fell back to its default keepalive_timeout (15s), which exceeds uvicorn's default timeout_keep_alive (5s). A pooled connection could be closed server-side while the client still considered it reusable, causing writes to fail mid-request. 2. _call() had no retry on connection-level failure. Added a retry-once path that rebuilds the request payload (not reuses the original, since it can be a one-shot async iterator/file stream) before retrying. Verified with a local load-test reproduction: before this fix, a burst of requests timed at the keep-alive boundary reliably produced a cluster of 500s; after, zero failures across repeated runs. Fixes bentoml#4971
Author
|
Hi @bojiang, just following up to see if you have time for a quick review on this fix. Thanks! |
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.
What does this PR address?
Fixes intermittent
httpx.RemoteProtocolError/aiohttpconnection resets when calling a dependent service viabentoml.depends()(e.g.ServiceA→ServiceB), surfaced to callers as unhandled 500s.Two related issues in
SessionManager/_call(_bentoml_impl/client/proxy2.py):tcp-scheme branch of_make_client()leftconnector=None, so aiohttp fell back to its defaultkeepalive_timeout(15s), which exceeds uvicorn's defaulttimeout_keep_alive(5s). A pooled connection could be closed server-side while the client still considered it reusable, causing writes to fail mid-request._call()had no retry on connection-level failure. Added a retry-once path that rebuilds the request payload (rather than reusing the original, since it can be a one-shot async iterator/file stream) before retrying.Fix:
keepalive_timeout=4.0on theTCPConnectorused fortcp-scheme sessions, keeping it safely under the server's 5s default.aiohttp.ClientConnectionError/aiohttp.ServerDisconnectedErrorand retries once with a freshly rebuilt payload.Testing:
tests/unit/_internal/client/test_session_manager.pyasserting the connector'skeepalive_timeout.@bentoml.serviceinstances, bursts of 200 requests timed against the keep-alive boundary): before this fix, this reliably produced a cluster of 500s; after, zero failures across repeated runs.Fixes #4971
Before submitting:
pre-commit run -ascript has passed (instructions)?