benchmark: fix error on server close in AsyncLocalStorage benchmark
- Closes #32501 (closed)
Fixes AsyncLocalStorage
type from benchmark/async_hooks/async-resource-vs-destroy.js
by adding undefined
check for the store (CLS context). Before this fix it could fail when the server is closed (and ALS instance is disabled), which may lead to calls to getCLS()
method of the benchmark in the following part of the request handling code:
setTimeout(() => {
// the server may be already closed when this (and the next one) callback is run
readFile(__filename, () => {
res.setHeader('content-type', 'application/json');
res.end(JSON.stringify({ cls: getCLS() }));
});
}, 10);
Other types within the benchmark already had similar checks, so that's why they weren't failing.
- Also removes redundant checks from
executionAsyncResource
type. Reason: the final implementation ofexecutionAsyncResource()
never returnsnull
.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines