mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
The ClosedPromiseHook records that pipeTo() and tee() install as the [[closedPromise]] of their reader and writer enqueued the watcher from whoever settled the record. The source-closed, source-errored and dest-errored steps of pipeTo() therefore ran in the async context of the code that closed or errored the stream, so the destination's close() and abort() and the source's cancel() observed the wrong AsyncLocalStorage store. Capture the async context frame when the hook is installed and register the reaction in it, as the spec's promise reaction would. Add a test that records the context each underlying source, sink and transformer callback observes across readable, writable, transform, pipe and tee scenarios, so scheduling shortcuts that drop the context are caught. Refs: https://github.com/nodejs/node/issues/66906 Refs: https://github.com/nodejs/node/pull/66424 Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: https://github.com/nodejs/node/pull/67052 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Paolo Insogna <paolo@cowtech.it>