mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user