You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(ext/node): per-request executionAsyncResource() for async_hooks (#34188)
## Summary
`executionAsyncResource()` from `node:async_hooks` previously returned a
fresh
`{}` on every call, so writes never persisted and the standard
CLS-on-async-
hooks pattern blew up with:
```
TypeError: Cannot destructure property 'state' of 'executionAsyncResource(...)[sym]'
as it is undefined.
```
This change tracks the current resource via an `AsyncVariable` (backed
by V8
continuation-preserved embedder data), defaulting to a shared top-level
singleton. The value propagates naturally across promise/await
transitions and
the existing setTimeout async-context capture/restore.
- `AsyncResource.runInAsyncScope` enters `this` as the current resource
for the
scope.
- The HTTP/1.1 server enters a per-request scope around the
`request`/`checkContinue`/`checkExpectation` emit so concurrent requests
get
isolated resources. Without this, every concurrent request would race on
anything stashed on the shared top-level resource.
Enables these two Node compat tests that the issue called out:
- `parallel/test-async-hooks-execution-async-resource.js`
- `parallel/test-async-hooks-execution-async-resource-await.js`
Closes denoland/orchid#129
## Test plan
- [x] Both target tests pass under `cargo test --test node_compat`
- [x] Full `async-hooks` and `async-local-storage` suites — no
regressions vs.
tests already enabled in `tests/node_compat/config.jsonc`
- [x] `parallel::test-http` suite — no new regressions in tests already
in
`config.jsonc` (one pre-existing flaky HTTP/2 test unrelated to this
change)
Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>
0 commit comments