Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 05ad792

Browse filesBrowse files
jasnellMylesBorins
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 <admin@stephenbelanger.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 33a98c4 commit 05ad792
Copy full SHA for 05ad792

File tree

Expand file treeCollapse file tree

3 files changed

+9
-80
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+9
-80
lines changed
Open diff view settings
Collapse file

‎doc/api/async_context.md‎

Copy file name to clipboardExpand all lines: doc/api/async_context.md
+7-17Lines changed: 7 additions & 17 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -116,35 +116,26 @@ 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: v19.2.0
126+
- version: REPLACEME
127+
pr-url: https://github.com/nodejs/node/pull/46386
128+
description: Removed experimental onPropagate option.
129+
- version:
130+
- v19.2.0
131+
- v18.13.0
127132
pr-url: https://github.com/nodejs/node/pull/45386
128133
description: Add option onPropagate.
129134
-->
130135

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-
138136
Creates a new instance of `AsyncLocalStorage`. Store is only provided within a
139137
`run()` call or after an `enterWith()` call.
140138

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-
148139
### `asyncLocalStorage.disable()`
149140

150141
<!-- YAML
@@ -834,5 +825,4 @@ const server = createServer((req, res) => {
834825
[`EventEmitter`]: events.md#class-eventemitter
835826
[`Stream`]: stream.md#stream
836827
[`Worker`]: worker_threads.md#class-worker
837-
[`async_hooks` Error handling]: async_hooks.md#error-handling
838828
[`util.promisify()`]: util.md#utilpromisifyoriginal
Collapse file

‎lib/async_hooks.js‎

Copy file name to clipboardExpand all lines: lib/async_hooks.js
+2-13Lines changed: 2 additions & 13 deletions
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

Collapse file

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

Copy file name to clipboardExpand all lines: test/async-hooks/test-async-local-storage-stop-propagation.js
-50Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.