Skip to content

fix(node): preserve AsyncLocalStorage context in unhandledRejection handlers#32264

Merged
bartlomieju merged 3 commits intodenoland:mainfrom
bartlomieju:fix/async-local-storage-unhandled-rejection
Feb 23, 2026
Merged

fix(node): preserve AsyncLocalStorage context in unhandledRejection handlers#32264
bartlomieju merged 3 commits intodenoland:mainfrom
bartlomieju:fix/async-local-storage-unhandled-rejection

Conversation

@bartlomieju
Copy link
Copy Markdown
Member

@bartlomieju bartlomieju commented Feb 22, 2026

Summary

  • Fixes AsyncLocalStorage.getStore() returning undefined inside unhandledRejection / unhandledrejection event handlers
  • Now matches Node.js behavior where the async context active at the time of rejection is preserved

Problem

import { AsyncLocalStorage } from 'node:async_hooks';
import process from 'node:process';

const store = new AsyncLocalStorage();

process.on('unhandledRejection', () => {
    console.log(store.getStore()); // Node: "data", Deno (before): undefined
});

await store.run("data", async () => {
    new Promise((_, reject) => setTimeout(() => reject(new Error('test')), 50));
});

Fixes #30135
Actually fixed in #32293, this just adds a test.

bartlomieju and others added 3 commits February 22, 2026 14:56
Adds a spec test verifying that AsyncLocalStorage context is preserved
when unhandledRejection handlers are invoked, matching Node.js behavior.

Refs denoland#30135
Depends on denoland/deno_core#1308

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bartlomieju bartlomieju enabled auto-merge (squash) February 23, 2026 21:19
@bartlomieju bartlomieju disabled auto-merge February 23, 2026 21:19
@bartlomieju bartlomieju enabled auto-merge (squash) February 23, 2026 21:19
@bartlomieju bartlomieju merged commit 87f3040 into denoland:main Feb 23, 2026
110 checks passed
@bartlomieju bartlomieju deleted the fix/async-local-storage-unhandled-rejection branch February 23, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AsyncLocalStorage not preserved in unhandledRejection (unlike Node)

2 participants