[🐞] `send(new Response(stream))` drops its `pipeTo` promise; a failed stream or a client that leaves exits a Bun server

Aperta Adatta ai principianti
#9,385 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@alloutflo ci sta già lavorando.

Dal 7/11/2026.

  • #9393 di @alloutflo — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
bun, typescript
Ambito
backend, web-dev

Direzione di ricerca

Leggi packages/qwik-router/src/middleware/request-handler/request-event-core.ts, in particolare send, e verifica come vengono gestite le promesse di pipeTo, write e close. La riproduzione nell’issue include sia uno stream in errore sia una disconnessione del client; usala per verificare che il server rimanga attivo dopo entrambi i casi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Which component is affected?

Qwik Router

Describe the bug

send() in the request event starts the write and does not wait for it or handle its failure. With a Response body it calls statusOrResponse.body.pipeTo(writableStream) and drops the returned promise; with a status and a body it drops the writer.write(...) and writer.close() promises the same way (packages/qwik-router/src/middleware/request-handler/request-event-core.ts, send).

When the pipe rejects, nothing handles the rejection. On Bun an unhandled rejection ends the process, so one failed streamed response takes the whole server down:

  1. The body stream errors (for example, an upstream the route is proxying resets its connection): error: <the stream's error>, exit code 1.
  2. The client leaves while the body is still streaming (closed tab, curl --max-time): AbortError: The connection was closed., exit code 1.

Any route that answers with send(new Response(stream)) is exposed (server-sent events, a proxied fetch body). In production this showed up as server processes exiting about a minute after a browser left a live feed.

Reproduced on 2.0.0-rc.4 and still present on main (a96a5fd25a, read 2026-11-06). I only tested Bun 1.4.4.

A one-line change makes both cases survive in the reproduction: handling the rejection of that pipeTo(...) (.catch(() => {}), or routing it to the request's error handling) keeps the server alive. I checked this by editing the built server of the reproduction. The write()/close() promises in the numeric branch need the same treatment.

Reproduction

https://github.com/ixcans/qwik-send-pipe-repro

Steps to reproduce
git clone https://github.com/ixcans/qwik-send-pipe-repro
cd qwik-send-pipe-repro
pnpm install
pnpm build
./check.sh

check.sh starts the built server, makes one request to /stream/?mode=error and one to /stream/?mode=endless (each against a fresh server), and reports whether the server is still alive:

mode=error curl exit=56 http=200  server alive after: NO (exit 1)
mode=endless curl exit=28 http=200  server alive after: NO (exit 1)

The only route is src/routes/stream/index.ts, which calls send(new Response(body)).

System Info
@qwik.dev/router 2.0.0-rc.4
@qwik.dev/core 2.0.0-rc.4
vite 8.3.6
bun 1.4.4 (Linux arm64)
adapter: @qwik.dev/router/adapters/bun-server
Lingua principale
TypeScript
Stelle
22.1k
Fork
1.4k
Merge medio
2g 6h
PR unite (30g)
96

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di QwikDev/qwik

Tutte le issue di QwikDev/qwik

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.