Skip to content

toWebRequest is not creating abort signal #1204

Description

@IlyaSemenov

Environment

  • h3@1.15.3
  • Node v22.16.0

Reproduction

The problem is clear by looking at the code — the signal property is not created:

h3/src/utils/request.ts

Lines 354 to 365 in ec77d6b

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

I would have created a demo reproduction with trpc-nuxt but StackBlitz currently has a problem running Nuxt apps, will do once nuxt/nuxt#33120 is fixed.

Describe the bug

toWebRequest is not creating the abort signal (which other libraries depend upon). That makes the code that uses the web requests created from h3 events to stuck forever when e.g. handling subscriptions.

Related issue: wobsoriano/trpc-nuxt#191

Additional context

I extended toWebRequest to pass the AbortSignal to work around the issue:

function toWebRequest(event: H3Event) {
  return event.web?.request || new Request(getRequestURL(event), {
    // @ts-ignore Undici option
    duplex: "half",
    method: event.method,
    headers: event.headers,
    body: getRequestWebStream(event),
    signal: (() => {
      const abortController = new AbortController()
      event.node.req.on("close", () => abortController.abort())
      return abortController.signal
    })(),
  })
}

Logs

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingv1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions