Skip to content

Commit 24b3972

Browse files
authored
fix: prevent streamable http wite after end from crashing the node process (#933)
1 parent b28c297 commit 24b3972

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/server/streamableHttp.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ export class StreamableHTTPServerTransport implements Transport {
303303
res.on("close", () => {
304304
this._streamMapping.delete(this._standaloneSseStreamId);
305305
});
306+
307+
// Add error handler for standalone SSE stream
308+
res.on("error", (error) => {
309+
this.onerror?.(error as Error);
310+
});
306311
}
307312

308313
/**
@@ -334,6 +339,11 @@ export class StreamableHTTPServerTransport implements Transport {
334339
}
335340
});
336341
this._streamMapping.set(streamId, res);
342+
343+
// Add error handler for replay stream
344+
res.on("error", (error) => {
345+
this.onerror?.(error as Error);
346+
});
337347
} catch (error) {
338348
this.onerror?.(error as Error);
339349
}
@@ -520,6 +530,11 @@ export class StreamableHTTPServerTransport implements Transport {
520530
this._streamMapping.delete(streamId);
521531
});
522532

533+
// Add error handler for stream write errors
534+
res.on("error", (error) => {
535+
this.onerror?.(error as Error);
536+
});
537+
523538
// handle each message
524539
for (const message of messages) {
525540
this.onmessage?.(message, { authInfo, requestInfo });

0 commit comments

Comments
 (0)