From 527b53c47ad660697b93aced24fe0393c8ba015e 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 PR-URL: https://github.com/nodejs/node/pull/33642 Reviewed-By: Benjamin Gruenbaum Reviewed-By: Ruben Bridgewater Reviewed-By: Colin Ihrig Reviewed-By: James M Snell Reviewed-By: Juan José Arboleda --- 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() })); });