Skip to content

fix(request): add AbortSignal to toWebRequest for client disconnect detection#1418

Open
LeSingh1 wants to merge 1 commit into
h3js:v1from
LeSingh1:fix/to-web-request-abort-signal
Open

fix(request): add AbortSignal to toWebRequest for client disconnect detection#1418
LeSingh1 wants to merge 1 commit into
h3js:v1from
LeSingh1:fix/to-web-request-abort-signal

Conversation

@LeSingh1

Copy link
Copy Markdown
Contributor

Summary

Closes #1204

Problem

toWebRequest creates a new Request() without an AbortSignal. This means downstream code that consumes request.signal (e.g. tRPC subscriptions, streaming handlers) can never detect when a client disconnects — the signal stays open forever.

Fix

When falling through to new Request(...), create an AbortController, wire its .abort() to event.node.req.on("close", ...), and pass signal: controller.signal to the Request constructor.

// Before
export function toWebRequest(event: H3Event) {
  return (
    event.web?.request ||
    new Request(getRequestURL(event), {
      duplex: "half",
      method: event.method,
      headers: event.headers,
      body: getRequestWebStream(event),
    })
  );
}

// After
export function toWebRequest(event: H3Event) {
  if (event.web?.request) {
    return event.web.request;
  }
  const controller = new AbortController();
  event.node.req.on("close", () => controller.abort());
  return new Request(getRequestURL(event), {
    duplex: "half",
    method: event.method,
    headers: event.headers,
    body: getRequestWebStream(event),
    signal: controller.signal,
  });
}

When event.web?.request is already present (i.e. a native web runtime), it carries its own signal — we return it as-is and skip the AbortController entirely.

Related

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 28c0c050-7916-4bc7-b1e3-f842b0aa0416

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pi0 pi0 added the v1 label Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants