Skip to content

fix(ext/workers): settle UserWorker.fetch without waiting for the request body pipe - #755

Open
da1suk8 wants to merge 1 commit into
supabase:mainfrom
da1suk8:fix/user-worker-fetch-settle
Open

da1suk8 wants to merge 1 commit into
supabase:mainfrom
da1suk8:fix/user-worker-fetch-settle

Conversation

@da1suk8

@da1suk8 da1suk8 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #742. UserWorker.fetch() waits for the request body pipe and the response with Promise.allSettled. When the body is a branch of a tee'd stream (req.clone()), the pipe never settles:

  • Once op_user_worker_fetch_send returns, with WorkerAlreadyRetired or with an early response, the Rust side cancels the request body resource.
  • The pipe's next write fails and pipeTo cancels its source. Cancelling one tee branch does not resolve until the other is cancelled too, and nobody reads the other.
  • So allSettled, and fetch(), never resolve.

fetch() now awaits only the response. The pipe keeps running in the background with its rejection swallowed, as before (#374). The early-response case is the runtime side of #737.

requestBodyRid is closed only when the dispatch fails. Closing it after a response too, as the first revision did, ends a Content-Length body short, so hyper aborts the connection and loses a response body still in flight (pointed out in #790).

Validation

Three integration tests, test_user_worker_fetch_*, on a new fixture main_retired_worker_fetch:

  • settles_when_worker_already_retired: no body, a passed-through body and a cloned body all reject with WorkerAlreadyRetired. On main the cloned case times out.
  • settles_when_response_arrives_before_body_is_sent: a cloned upload to a worker that returns 413 without reading it. On main it times out.
  • relays_response_body_that_follows_the_head: a Content-Length body that has not arrived yet, and a response body sent 100 ms after its head. On main it times out; with the resource closed on every exit, reading the body fails.

The other integration tests behave the same as with main's fetch() on my machine (macOS). clippy and the format check pass.

Limitations

Does not fix #790: the Rust side still cancels the request body once the response head returns, so a response body still in flight when the next request-body chunk arrives is lost, as on main.

@da1suk8

da1suk8 commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@nyannyacha @kallebysantos Gentle ping. This still merges cleanly on current main (after #763). The workflow run has not been approved yet, so CI has not run on it; could one of you approve it? Happy to adjust anything in the approach.

@da1suk8
da1suk8 force-pushed the fix/user-worker-fetch-settle branch from 40fab29 to 00e071e Compare December 2, 2026 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant