Skip to content

Commit bfffb97

Browse files
addaleaxcodebytere
authored andcommitted
benchmark: fix async-resource benchmark
In the benchmark, because it performs asynchronous operations before writing its HTTP replies, the underlying socket can be closed by the peer before the response is written. Since 28e6626, that means that attempting to `.end()` the HTTP response results in an uncaught exception, breaking the benchmark. Fix that by checking whether the response object has been destroyed or not before attempting to call `.end()`. #33591 PR-URL: #33642 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]>
1 parent f1a8108 commit bfffb97

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

benchmark/async_hooks/async-resource-vs-destroy.js

+2
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ function getServeAwait(getCLS, setCLS) {
138138
setCLS(Math.random());
139139
await sleep(10);
140140
await read(__filename);
141+
if (res.destroyed) return;
141142
res.setHeader('content-type', 'application/json');
142143
res.end(JSON.stringify({ cls: getCLS() }));
143144
};
@@ -148,6 +149,7 @@ function getServeCallbacks(getCLS, setCLS) {
148149
setCLS(Math.random());
149150
setTimeout(() => {
150151
readFile(__filename, () => {
152+
if (res.destroyed) return;
151153
res.setHeader('content-type', 'application/json');
152154
res.end(JSON.stringify({ cls: getCLS() }));
153155
});

0 commit comments

Comments
 (0)