From 73d01d809d179e5496e6483c57dfd2add3e44e23 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 29 May 2020 23:28:25 +0200 Subject: [PATCH] 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 28e6626ce7020, 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()`. https://github.com/nodejs/node/issues/33591 --- benchmark/async_hooks/async-resource-vs-destroy.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/benchmark/async_hooks/async-resource-vs-destroy.js b/benchmark/async_hooks/async-resource-vs-destroy.js index 52e5e543a6a08d..09898bbe52f939 100644 --- a/benchmark/async_hooks/async-resource-vs-destroy.js +++ b/benchmark/async_hooks/async-resource-vs-destroy.js @@ -138,6 +138,7 @@ function getServeAwait(getCLS, setCLS) { setCLS(Math.random()); await sleep(10); await read(__filename); + if (res.destroyed) return; res.setHeader('content-type', 'application/json'); res.end(JSON.stringify({ cls: getCLS() })); }; @@ -148,6 +149,7 @@ function getServeCallbacks(getCLS, setCLS) { setCLS(Math.random()); setTimeout(() => { readFile(__filename, () => { + if (res.destroyed) return; res.setHeader('content-type', 'application/json'); res.end(JSON.stringify({ cls: getCLS() })); });