Skip to content

fix(zone.js): keep the Node.js async context in microtasks - #71826

Open
SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:fix-zone-als
Open

SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:fix-zone-als

Conversation

@SkyZeroZx

Copy link
Copy Markdown
Contributor

Previously, then() recorded only Zone.current, and every promise reaction in the process is drained from one shared microtask. Each reaction, the task hooks around it and the reporting of its errors ran in the async context of whatever scheduled that microtask, so on the server AsyncLocalStorage.getStore() could return the store of another request. Since NgZone runs change detection from those hooks, a whole tick could run as the wrong request.

Capture the async context when the callback is registered and run the task inside it, as Node.js recommends for custom thenables. Set __Zone_disable_asyncContext to opt out.

Fixes #71825

Previously, `then()` recorded only `Zone.current`, and every promise reaction in the process is drained from one shared microtask. Each reaction, the task hooks around it and the reporting of its errors ran in the async context of whatever scheduled that microtask, so on the server `AsyncLocalStorage.getStore()` could return the store of another request. Since `NgZone` runs change detection from those hooks, a whole tick could run as the wrong request.

Capture the async context when the callback is registered and run the task inside it, as Node.js recommends for custom thenables. Set `__Zone_disable_asyncContext` to opt out.

Fixes angular#71825
@pullapprove
pullapprove Bot requested a review from alan-agius4 November 5, 2026 02:18
@angular-robot angular-robot Bot added the area: zones Issues related to zone.js label Nov 5, 2026
@ngbot ngbot Bot added this to the Backlog milestone Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: zones Issues related to zone.js

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zone.js: Promise reactions cause cross request AsyncLocalStorage context leakage in SSR

1 participant