Skip to content

Commit b1bde69

Browse files
jasnelldanielleadams
authored andcommitted
async_hooks: remove experimental onPropagate option
The `onPropagate` option for `AsyncLocalStorage` is problematic for a couple of reasons: 1. It is not expected to be forwards compatible in any way with the upcoming TC-39 `AsyncContext` proposal. 2. It introduces a non-trivial O(n) cost invoking a JavaScript callback for *every* AsyncResource that is created, including every Promise. While it is still experimental, I recommend removing it while we can revisit the fundamental use cases in light of the coming `AsyncContext` proposal. Refs: #46374 PR-URL: #46386 Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Vladimir de Turckheim <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
1 parent f088ce2 commit b1bde69

File tree

3 files changed

+6
-79
lines changed

3 files changed

+6
-79
lines changed

doc/api/async_context.md

+4-16
Original file line numberDiff line numberDiff line change
@@ -116,35 +116,24 @@ Each instance of `AsyncLocalStorage` maintains an independent storage context.
116116
Multiple instances can safely exist simultaneously without risk of interfering
117117
with each other's data.
118118

119-
### `new AsyncLocalStorage([options])`
119+
### `new AsyncLocalStorage()`
120120

121121
<!-- YAML
122122
added:
123123
- v13.10.0
124124
- v12.17.0
125125
changes:
126+
- version: REPLACEME
127+
pr-url: https://github.com/nodejs/node/pull/46386
128+
description: Removed experimental onPropagate option.
126129
- version: v18.13.0
127130
pr-url: https://github.com/nodejs/node/pull/45386
128131
description: Add option onPropagate.
129132
-->
130133

131-
> Stability: 1 - `options.onPropagate` is experimental.
132-
133-
* `options` {Object}
134-
* `onPropagate` {Function} Optional callback invoked before a store is
135-
propagated to a new async resource. Returning `true` allows propagation,
136-
returning `false` avoids it. Default is to propagate always.
137-
138134
Creates a new instance of `AsyncLocalStorage`. Store is only provided within a
139135
`run()` call or after an `enterWith()` call.
140136

141-
The `onPropagate` is called during creation of an async resource. Throwing at
142-
this time will print the stack trace and exit. See
143-
[`async_hooks` Error handling][] for details.
144-
145-
Creating an async resource within the `onPropagate` callback will result in
146-
a recursive call to `onPropagate`.
147-
148137
### `asyncLocalStorage.disable()`
149138

150139
<!-- YAML
@@ -830,5 +819,4 @@ const server = createServer((req, res) => {
830819
[`EventEmitter`]: events.md#class-eventemitter
831820
[`Stream`]: stream.md#stream
832821
[`Worker`]: worker_threads.md#class-worker
833-
[`async_hooks` Error handling]: async_hooks.md#error-handling
834822
[`util.promisify()`]: util.md#utilpromisifyoriginal

lib/async_hooks.js

+2-13
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const {
2323
const { kEmptyObject } = require('internal/util');
2424
const {
2525
validateFunction,
26-
validateObject,
2726
validateString,
2827
} = require('internal/validators');
2928
const internal_async_hooks = require('internal/async_hooks');
@@ -275,17 +274,9 @@ const storageHook = createHook({
275274
});
276275

277276
class AsyncLocalStorage {
278-
constructor(options = kEmptyObject) {
279-
validateObject(options, 'options');
280-
281-
const { onPropagate = null } = options;
282-
if (onPropagate !== null) {
283-
validateFunction(onPropagate, 'options.onPropagate');
284-
}
285-
277+
constructor() {
286278
this.kResourceStore = Symbol('kResourceStore');
287279
this.enabled = false;
288-
this._onPropagate = onPropagate;
289280
}
290281

291282
disable() {
@@ -312,9 +303,7 @@ class AsyncLocalStorage {
312303
_propagate(resource, triggerResource, type) {
313304
const store = triggerResource[this.kResourceStore];
314305
if (this.enabled) {
315-
if (this._onPropagate === null || this._onPropagate(type, store)) {
316-
resource[this.kResourceStore] = store;
317-
}
306+
resource[this.kResourceStore] = store;
318307
}
319308
}
320309

test/async-hooks/test-async-local-storage-stop-propagation.js

-50
This file was deleted.

0 commit comments

Comments
 (0)