You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@Sse() stream hangs when event data can't be serialized (BigInt, circular object, number) #18024
If an @Sse() handler emits an event whose data can't be serialized, the stream just stops. The client gets the events sent before it and then nothing: no event: error, none of the following events, and the response is never ended. Nothing is logged on the server.
It happens with:
a BigInt (e.g. from a Prisma BigInt column) or a circular object in data, where JSON.stringify throws
a number or a boolean as data, e.g. { data: 1 }, or of(1, 2) returned directly, which Nest wraps as { data: 1 }. serializeSseLines() calls .split() on it.
If it's the first event, the client gets a 200 with the SSE headers and an empty stream that never ends, instead of a 500.
SseStream._transform commits the headers and then serializes the data (sse-stream.ts#L6-L19, #L153). The throw escapes stream.write(), so the transform callback is never called and the stream stays stuck mid-write. The event: error written by catchError in RouterResponseController.sse() (router-response-controller.ts#L211) and the final end() are queued behind it and never sent. Since the headers are already committed by then, a bad first event takes the same path instead of rejecting.
curl -N --max-time 3 http://localhost:3000/sse prints event 1, then waits until curl times out
curl -i --max-time 3 http://localhost:3000/sse-first returns 200 with the SSE headers, no events, and never ends
curl -N --max-time 3 http://localhost:3000/sse-number sends no events and never ends
Expected behavior
Numbers and booleans sent like other values (data: 1). For data that really can't be serialized, the same handling as other errors in the stream: an event: error with the message (Do not know how to serialize a BigInt) and the end of the response, or a 500 if no event was sent yet.
Activity
kamilmysliwiec commentedon Oct 8, 2026
lets track this here #18025
fix(core): end sse streams whose event data cannot be serialized
fix(core): end sse streams whose event data cannot be serialized (#18025