Skip to content

Outbound fetch fails when a pooled keep-alive connection is closed by the server (flaky fetch/misc@all-autogates) #8100

Closed

Description

@bartlomieju

//src/wpt:fetch/misc@all-autogates fails intermittently, mostly on the ARM debug job, in cross-origin-resource-policy/syntax.any.js ("Parsing Cross-Origin-Resource-Policy: same"):

workerd/jsg/util.c++:416: info: exception = rust/worker/ffi.rs:110: disconnected: client error (SendRequest)
Error: Network connection lost.  { retryable: true }

Seen on unrelated PRs: #7969 (twice, e.g. https://github.com/cloudflare/workerd/actions/runs/41040553867/job/124014037312), biwanczuk/rust-io-context-await-io, biwanczuk/rust-jsg-oneof.

Cause

Since 9d81827 ("server: reuse outbound connections", #7714), the kj-hyper client (src/rust/cxx/kj-hyper/client.rs) keeps connections in hyper-util's legacy pool.

  1. The previous test, content-length/api-and-duplicate-headers.any.js, fetches resources/identical-duplicates.asis. wptserve's AsIsHandler writes the file's bytes as the response, an HTTP/1.1 response with Content-Length: 6 and no Connection: close. Then it sets close_connection = True and closes the socket.
  2. hyper sees a complete keep-alive response and returns the connection to the pool.
  3. In our harness HTTP_REMOTE_ORIGIN is the same as HTTP_ORIGIN (src/wpt/harness/common.ts), so syntax.any.js's first fetch, a few ms later, checks out the same connection.
  4. If hyper has not yet seen the server close the socket, it writes the request onto it and gets EOF instead of a response. hyper-util retries only requests it never wrote (TrySendError::Retryable / retry_canceled_requests), so this one ends as a SendRequest error.

This isn't specific to WPT. Any origin that closes idle keep-alive connections without Connection: close, for example a server whose keep-alive timeout is shorter than our 5 s idle_timeout, can fail a request this way. Before 9d81827, every request used a new connection.

Possible fix

Retry once, as browsers do, when a replayable request (an empty GET/HEAD, which request() already treats as unframed) fails on a reused connection before any response bytes arrive. hyper-util's error doesn't say whether the connection was reused. One way to track it is a per-connection marker attached with Connected::extra(): a received response sets it, and on error it's read back with err.connect_info() + Connected::get_extras().

To make it deterministic in a kj-hyper test, have the server answer one request, then read the next request and close without responding.

A test-only workaround is to make the sidecar send Connection: close for .asis responses. That would leave the production race in place.

Activity

  1. added
    bug
    on Oct 30, 2026
  2. npaun commented on Oct 30, 2026

    @npaun
    Member

    I assigned us both just so it comes up when I look at issues I'm interested in. Hopefully that's not going to do anything annoying in your workflow

  3. bartlomieju commented on Oct 30, 2026

    @bartlomieju
    CollaboratorAuthor

    @npaun I think I will try to address it right now, I'm hitting it very frequently on CI today.... actually it's a different problem, so this one is up for grabs

  4. bartlomieju commented on Nov 20, 2026

    @bartlomieju
    CollaboratorAuthor

    Verified with workerd 1.20261119.1: GET and HEAD requests recover when a reused keep-alive connection closes without responding. A deterministic reproduction passed 40 retries across compatibility dates 2026-10-30 and 2026-11-19, with server logs confirming retries used fresh connections. Closing as resolved.

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

Metadata

Metadata

Labels

bugtests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions