fix(core): retry an HTTP response read interrupted by a signal - #252
Open
rominf wants to merge 1 commit into
Open
fix(core): retry an HTTP response read interrupted by a signal#252rominf wants to merge 1 commit into
rominf wants to merge 1 commit into
Conversation
The bounded response reader treated every unrecognised `read` error as a transport failure, so a signal delivered to the reading thread — which fails the read with `EINTR` — reported a healthy endpoint as unreachable. `SA_RESTART` does not prevent this: Linux never restarts a socket read that has a receive timeout set, and the reader sets one on every pass. Any handler in the process is enough, and `crossterm`'s `SIGWINCH` hook is linked into the CLI. `EINTR` says nothing is wrong with the connection, so read again; the existing deadline still bounds the total wait. The visible cost was a service health probe failing at random. Because a failed inference probe is latched onto the service record for the 15s retry interval, one interrupted read also made every later check in that window report the service as not ready. In the test suite this showed up as `local_provider_default_chat_requires_builtin_qwen_assistant` failing three ways — "Broken pipe", `no_ready_local_service`, and `no_ready_builtin_assistant_service` — in 3 of 20 suite runs, and in none of 20 after the change. The regression test drives a real signal at the reading thread with a handler installed with `SA_RESTART`, and fails without the fix. Signed-off-by: Roman Inflianskas <Roman.Inflianskas@amd.com>
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.
tests/e2e-cucumber/expectations.tomlfor the fixed ticket ID and removed/narrowed any now-stale xfail rows. (No matching rows.)Summary
EINTRas retryable in the bounded HTTP response reader instead of failing the request.Root cause
read_http_response_boundedhandledWouldBlockandTimedOutand treated every otherreaderror as a transport failure. A signal delivered while the client is parked inreadfails it withEINTR, which fell into that catch-all.SA_RESTARTdoes not prevent it. Linux never restarts a socket read that has a receive timeout set (signal(7), "Interruption of system calls"), and this reader sets one on every pass so the total wait stays bounded. Any signal handler in the process is enough to trigger it, andcrossterm'sSIGWINCHhook is linked into the CLI.EINTRsays nothing is wrong with the connection, so the read should simply be retried — which is whatstd's ownread_to_enddoes, and why the siblingread_tcp_stream_to_stringhelper was never affected.Verification
Found by instrumenting the client while reproducing a flaky test:
Server-side timing showed 42ms from accept to read, ruling out a slow peer or a starved thread.
The regression test drives real signals at the reading thread with
pthread_killwhile it waits on a deliberately late response, with the handler installed usingSA_RESTARTto show the flag is not what protects the read. It fails without the fix, with the same "Broken pipe" symptom the original flake produced (the client aborts, so the server's write hitsEPIPE).In the test suite this surfaced as
providers::tests::local_provider_default_chat_requires_builtin_qwen_assistantfailing three different ways —Broken pipe,no_ready_local_service, andno_ready_builtin_assistant_service, all explained by that one aborted read. Over 20 consecutivecargo test -p rocm --bin rocmruns:Also run:
cargo clippy --locked --workspace --all-targets -- -D warnings,cargo clippy --locked -p e2e-cucumber --test e2e -- -D warnings,cargo test --workspace --all-targets --exclude e2e-cucumber,prek run --all-files.Scope and gaps
SA_RESTART— is documented for Linux; BSD-derived kernels may restart the read, which would leave the test passing without reaching the retry. CI has no macOS runner to tell the difference. The fix itself is unconditional.read_close_delimited_sse_bodyinapps/rocm/src/providers.rshas the same gap on the chat-streaming path. Same class of bug, but I have no reproduction for it, so it is not folded into a fix whose repro I can demonstrate. Happy to follow up.