diff options
author | Anna Henningsen <anna@addaleax.net> | 2020-05-29 23:28:25 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-06-06 17:36:52 +0200 |
commit | f5ed5fe06867884254fd885eca01b6ee5d21ac48 (patch) | |
tree | c7f94544621ab67194e69d03cc9dd01d54261ce6 /benchmark | |
parent | 065426c90af4ae102dc66f7f801478deec368be5 (diff) | |
download | ios-node-v8-f5ed5fe06867884254fd885eca01b6ee5d21ac48.tar.gz ios-node-v8-f5ed5fe06867884254fd885eca01b6ee5d21ac48.tar.bz2 ios-node-v8-f5ed5fe06867884254fd885eca01b6ee5d21ac48.zip |
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
PR-URL: https://github.com/nodejs/node/pull/33642
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/async_hooks/async-resource-vs-destroy.js | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/benchmark/async_hooks/async-resource-vs-destroy.js b/benchmark/async_hooks/async-resource-vs-destroy.js index 52e5e543a6..09898bbe52 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() })); }); |