Skip to content

Apply the request timeout to response body reads in RawHttpMessageHandler - #4734

Open
uhvesta wants to merge 2 commits into
actions:mainfrom
uhvesta:fix/raw-handler-response-body-timeout
Open

uhvesta wants to merge 2 commits into
actions:mainfrom
uhvesta:fix/raw-handler-response-body-timeout

Conversation

@uhvesta

@uhvesta uhvesta commented Sep 23, 2026 •

Copy link
Copy Markdown

Fixes #4668
Fixes #4703

Problem

RawHttpClientBase turns off HttpClient.Timeout, and RawHttpMessageHandler's SendTimeout only covers the request until the response headers arrive. If a server sends the headers and then stops sending the body, the read waits forever unless the caller cancels.

That's what happens in #4668 and #4703. After Acknowledging runner request, the listener POSTs to acquirejob, the body stalls after the headers, and the listener's main loop blocks on that read. Nothing else in the runner can cancel it, because session restarts, self-updates and ephemeral shutdown all run on that same loop, so the runner never takes another job or exits. About 10 minutes later GitHub fails the job with "The self-hosted runner lost communication with the server", but the process still looks healthy and someone has to kill it by hand. Under ARC, each stuck pod keeps taking up a runner slot.

Approach

Response bodies have never timed out, and something may rely on that (a large or slow response that takes longer than SendTimeout to arrive), so this adds an idle timeout rather than a deadline on the whole body:

  • Buffered response bodies time out after SendTimeout with no data. Each read restarts the timer, so a slow body that keeps arriving still completes. A stall fails with the same TimeoutException as a header timeout.
  • The timeout runs when HttpClient buffers the body, after VssHttpRetryMessageHandler has acted on the status. Reading the body inside the handler instead would put body errors inside the retry loop and change which requests get retried.
  • ResponseHeadersRead requests (such as results uploads) aren't buffered and get no body timeout. RawHttpClientBase now passes the completion option to the handler so it can tell.

For acquirejob, that means a TimeoutException after 100 seconds with no data by default (GITHUB_ACTIONS_RUNNER_HTTP_TIMEOUT allows 100–1200). RunServer tries up to 5 times, then the listener goes back to polling.

Behavior

Scenario main This PR
Body stops arriving after the headers Hangs forever TimeoutException after SendTimeout with no data
Slow body that keeps arriving Completes Completes
Retryable status (503, 429) with a stalled body, retries left Retried from the status Same

Caller cancellation, ResponseHeadersRead streaming and a disabled SendTimeout behave as before.

Testing

The new RawHttpMessageHandlerL0 tests run a real SocketsHttpHandler against a loopback TCP server, so they go through the actual HTTP stack without network access. The stall tests hang on main (a watchdog turns the hang into a failure) and pass here. The rest pass on both and cover the behavior above that shouldn't change.

@uhvesta
uhvesta force-pushed the fix/raw-handler-response-body-timeout branch from 5d84fae to a57b8ad Compare September 23, 2026 06:34
RawHttpClientBase disables HttpClient.Timeout and SendTimeout stops at
the response headers, so a body that stalls after the headers (seen on
acquirejob) hangs the listener. Give buffered bodies an idle timeout of
SendTimeout, applied after the retry handler has seen the status.
@uhvesta
uhvesta force-pushed the fix/raw-handler-response-body-timeout branch from 28d37c4 to 3567f0d Compare September 23, 2026 22:33
@uhvesta
uhvesta marked this pull request as ready for review September 23, 2026 22:49
@uhvesta
uhvesta requested a review from a team as a code owner September 23, 2026 22:49
Copilot AI lite review requested due to automatic review settings September 23, 2026 22:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

Direct handler users need supported completion-option propagation and test coverage.

Review effort: Lite
Findings: None

What changed in this PR

Adds idle timeouts for buffered response-body reads while preserving streaming and retry behavior.

Changes:

  • Propagates HttpCompletionOption through raw clients.
  • Wraps buffered response content with resettable timeouts.
  • Adds loopback tests for stalls, retries, cancellation, and streaming.
File Summary
src/​Test/​L0/​Sdk/​RawHttpMessageHandlerL0.cs Tests timeout and compatibility behavior.
src/​Sdk/​WebApi/​WebApi/​RawHttpClientBase.cs Passes completion options to handlers.
src/​Sdk/​Common/​Common/​RawHttpMessageHandler.cs Implements response-body timeout handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Addresses Copilot review feedback that the fallback for requests sent
outside RawHttpClientBase had no test coverage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants