Skip to content

fix(1.x): abort event.request.signal when the client disconnects - #2340

Merged
lxsmnsyc merged 1 commit into
1.xfrom
fix/abort-signal-1x
Oct 13, 2026
Merged

lxsmnsyc merged 1 commit into
1.xfrom
fix/abort-signal-1x

Conversation

@lxsmnsyc

Copy link
Copy Markdown
Member

Fixes #1753 on the 1.x line.

On Node, event.request.signal never aborts, so an API route cannot tell when the client goes away and keeps running. The issue's use case is an AI chat route that keeps streaming tokens from the provider after the user cancels.

Cause

createFetchEvent uses vinxi's getWebRequest. On Node, vinxi's toWebRequestH3 builds the Request without a signal, so the signal is a fresh one that nothing ever aborts. This is why the reporter had to fall back to event.nativeEvent.node.req.on("close").

Fix

createFetchEvent now wraps the request with a signal that aborts when the Node response closes before it was fully sent, the same rule srvx uses in 2.0:

  • If the request errored, abort with that error.
  • Otherwise, abort only if res.writableEnded is false, so a normal finish does not abort.

The new signal is combined with the original one using AbortSignal.any. On web runtimes, h3 gives the event the platform request, whose signal already works, and it keeps working. h3 uses node-mock-http for the Node objects there. Its response sets writableEnded before it emits close, and destroy() removes listeners, so it cannot trigger a false abort. 1.x requires Node 22, so AbortSignal.any is available.

The wrapped request takes over the original request's body, so it is also stored on event.web.request. Later getWebRequest calls then return the same request and can still read the body.

Testing

  • Reproduced on a production build of apps/tests from this branch, with a temporary API route that listens for abort:
    • Before: the client disconnected at 500ms and the server ran the full 3 seconds with aborted = false.
    • After: the abort fired and the route stopped at about 500ms. A request that finished normally still saw aborted = false.
  • Added 5 tests in fetchEvent.spec.ts: abort on early close, no abort after a full send, abort with the request error, keeping the platform signal, and keeping the body on the shared request. The 2 tests for the bug fail without the fix.
  • @solidjs/start: test:ci (95 tests), typecheck and build pass.
  • apps/tests: unit:ci and the full Cypress suite pass against the production build (19 tests, including the 13 server function tests that send request bodies).

Note: this targets 1.x, so merging it will not close #1753 on its own.

🤖 Generated with Claude Code

On Node, vinxi builds the web request without a signal tied to the
connection, so event.request.signal never aborted and API routes kept
running after the client went away.

- Wrap the request with a signal that aborts when the response closes
  before it was fully sent, or with the request error if the request failed.
- Combine it with the original signal using AbortSignal.any, so the
  platform signal on web runtimes still applies.
- Store the wrapped request on event.web, since it takes over the body and
  later getWebRequest calls must return the same request.

Fixes #1753.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cf8926d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/start Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Oct 13, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@solidjs/start@2340

commit: cf8926d

@lxsmnsyc
lxsmnsyc merged commit e36e23c into 1.x Oct 13, 2026
7 checks passed
@lxsmnsyc
lxsmnsyc deleted the fix/abort-signal-1x branch October 13, 2026 04:53
@lxsmnsyc lxsmnsyc mentioned this pull request Oct 16, 2026
2 tasks done
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.

2 participants