fix: prevent streamable http wite after end from crashing the node process (#933)

This commit is contained in:
Jakub Kopecký 2025-09-17 11:51:37 +02:00 • committed by GitHub
commit 24b3972931
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -303,6 +303,11 @@ export class StreamableHTTPServerTransport implements Transport {
res.on("close", () => {
this._streamMapping.delete(this._standaloneSseStreamId);
});
// Add error handler for standalone SSE stream
res.on("error", (error) => {
this.onerror?.(error as Error);
});
}
/**
@ -334,6 +339,11 @@ export class StreamableHTTPServerTransport implements Transport {
}
});
this._streamMapping.set(streamId, res);
// Add error handler for replay stream
res.on("error", (error) => {
this.onerror?.(error as Error);
});
} catch (error) {
this.onerror?.(error as Error);
}
@ -520,6 +530,11 @@ export class StreamableHTTPServerTransport implements Transport {
this._streamMapping.delete(streamId);
});
// Add error handler for stream write errors
res.on("error", (error) => {
this.onerror?.(error as Error);
});
// handle each message
for (const message of messages) {
this.onmessage?.(message, { authInfo, requestInfo });