Skip to content

api: keep Hyperdrive subrequest channel alive for the CONNECT stream - #7908

Merged
bartlomieju merged 4 commits into
mainfrom
biwanczuk/fix-hyperdrive-worker-designator
Oct 23, 2026
Merged

bartlomieju merged 4 commits into
mainfrom
biwanczuk/fix-hyperdrive-worker-designator

Conversation

@bartlomieju

Copy link
Copy Markdown
Collaborator

Hyperdrive::connectToDb() created a raw HTTP client over the subrequest
channel and returned the connection stream, letting both the client and the
channel die with the coroutine frame.

When the designator resolves to a Worker service, the channel owns the
WorkerEntrypoint serving the CONNECT, whose deferred drain later
reads waitUntilTasks on a destroyed object and crashes the process with
SIGSEGV.

This PR attaches client and channel to the returned stream so they live as
long as the connection.

Fixes #6901

Supersedes #7719 (opened from a fork, so CI could not run).

Hyperdrive::connectToDb() created a raw HTTP client over the subrequest
channel and returned the connection stream, letting both the client and
the channel die with the coroutine frame. When the designator resolves
to a Worker service, the channel owns the WorkerEntrypoint serving the
CONNECT, whose deferred drain later reads waitUntilTasks on a destroyed
object and crashes the process with SIGSEGV. Attach client and channel
to the returned stream so they live as long as the connection.

Fixes #6901
@clanky-the-clanker

Copy link
Copy Markdown

✅ Approved — The fix makes the connection stream own the HTTP client, and the client owns the subrequest channel, so the WorkerEntrypoint serving the CONNECT now lives as long as the connection. A server test covers the Worker-designator path that used to crash. No issues found.

The decision is advisory: this comment never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

No issues found.

  • src/workerd/api/hyperdrive.c++:
    • asHttpClient(kj::Own<WorkerInterface>) takes ownership of the subrequest channel.
    • Attaching the returned client to connectReq.connection therefore keeps both the client and the channel alive for as long as the stream exists. This fixes the use-after-free of the WorkerEntrypoint when its deferred drain runs.
    • On non-2xx and error paths the client and channel are still destroyed with the coroutine frame. That is safe because no stream has been handed out.
    • The new workerd/io/worker-interface.h include is needed for asHttpClient.
  • src/workerd/server/server-test.c++: the new test covers a Hyperdrive binding whose designator resolves to a Worker connect() handler, which is the scenario reported in Hyperdrive.connect() crashes the whole process with SIGSEGV when the binding's designator points at a Worker service instead of an external service #6901.
  • Not verified: this review did not run the test, so it does not confirm that the test crashes without the fix.

📝 Documentation: ✅ LGTM

No documentation issues found.


Reviewed commit: 07ac7b07

@ask-bonk

ask-bonk Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

LGTM!


Reviewed commit: 07ac7b07 · github run

@bartlomieju
bartlomieju merged commit 56f8447 into main Oct 23, 2026
57 of 59 checks passed
@bartlomieju
bartlomieju deleted the biwanczuk/fix-hyperdrive-worker-designator branch October 23, 2026 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hyperdrive.connect() crashes the whole process with SIGSEGV when the binding's designator points at a Worker service instead of an external service

2 participants