-
Notifications
You must be signed in to change notification settings - Fork 296
Open
Labels
Description
Environment
- [email protected]
- Node v22.16.0
Reproduction
The problem is clear by looking at the code — the signal property is not created:
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
pi0 and kricsleo