fix(http): catch errors thrown by response event handlers

Previously, errors thrown by user-provided response event handlers would
crash the process. This happened because the try-finally block around
emit("response", res) had no catch clause.

This fix adds a catch block to handle errors thrown by response handlers,
matching Node.js behavior where such errors don't crash the process.

Fixes test/js/node/test/parallel/test-http-server-stale-close.js
This commit is contained in:
Claude Bot
2025-10-06 12:28:47 +00:00
parent 83060e4b3e
commit bf65f93c3c

View File

@@ -426,6 +426,10 @@ function ClientRequest(input, options, cb) {
if (self.aborted || !self.emit("response", res)) {
res._dump();
}
} catch (err) {
// Errors thrown by user's response handler should not crash the process
// This matches Node.js behavior
if (!!$debug) globalReportError(err);
} finally {
maybeEmitClose();
if (res.statusCode === 304) {