From 05ad792a075046d66d43f1abcf1eefdd467e4061 Mon Sep 17 00:00:00 2001 From: James M Snell Date: Fri, 27 Jan 2023 14:03:51 -0800 Subject: [PATCH] async_hooks: remove experimental onPropagate option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/issues/46374 PR-URL: https://github.com/nodejs/node/pull/46386 Reviewed-By: Stephen Belanger Reviewed-By: Vladimir de Turckheim Reviewed-By: Geoffrey Booth Reviewed-By: Benjamin Gruenbaum Reviewed-By: Gerhard Stöbich Reviewed-By: Chengzhong Wu --- doc/api/async_context.md | 24 +++------ lib/async_hooks.js | 15 +----- ...st-async-local-storage-stop-propagation.js | 50 ------------------- 3 files changed, 9 insertions(+), 80 deletions(-) delete mode 100644 test/async-hooks/test-async-local-storage-stop-propagation.js diff --git a/doc/api/async_context.md b/doc/api/async_context.md index ce63e639f6ee59..94af6b016b1e74 100644 --- a/doc/api/async_context.md +++ b/doc/api/async_context.md @@ -116,35 +116,26 @@ Each instance of `AsyncLocalStorage` maintains an independent storage context. Multiple instances can safely exist simultaneously without risk of interfering with each other's data. -### `new AsyncLocalStorage([options])` +### `new AsyncLocalStorage()` -> Stability: 1 - `options.onPropagate` is experimental. - -* `options` {Object} - * `onPropagate` {Function} Optional callback invoked before a store is - propagated to a new async resource. Returning `true` allows propagation, - returning `false` avoids it. Default is to propagate always. - Creates a new instance of `AsyncLocalStorage`. Store is only provided within a `run()` call or after an `enterWith()` call. -The `onPropagate` is called during creation of an async resource. Throwing at -this time will print the stack trace and exit. See -[`async_hooks` Error handling][] for details. - -Creating an async resource within the `onPropagate` callback will result in -a recursive call to `onPropagate`. - ### `asyncLocalStorage.disable()`