You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importassertfrom'node:assert'globalThis.addEventListener('unhandledrejection',(e)=>{console.error('unhandled rejection:',e.reason)})constasyncFunction=async(name)=>{thrownewError(`this function rejects: ${name}`)}exportconstAssertBased={asynctest(ctrl,env,ctx){assert.rejects(async()=>asyncFunction('A'))},}exportconstManual={asynctest(ctrl,env,ctx){consterror=awaitPromise.resolve().then(function(){returnasyncFunction('B')}).then(function(){returnnull}).catch(function(e){returne})// console.log('Got this error:', error)},}exportconstTryCatch={asynctest(ctrl,env,ctx){try{awaitPromise.resolve('C').then(asyncFunction)}catch(error){// console.log('Got this error:', error)}},}
In all these cases, A, B, and C are logged as unhandled rejections, while they are, in fact, handled.
As a work-around, unhandledrejection + rejectionhandled + setTimeout(0) works fine
A fix could like like that here - just delay all unhandledrejection fires until microtask queue completes and then fire those that weren't handled until they are fired
Activity
jasnell commentedon Feb 6, 2026
Yep, we've needed to refine the unhandled rejection book keeping for a while now.
ChALkeR commentedon Feb 8, 2026
As a work-around,
unhandledrejection+rejectionhandled+setTimeout(0)works fineA fix could like like that here - just delay all
unhandledrejectionfires until microtask queue completes and then fire those that weren't handled until they are firedfix(workerd): end connections without an unhandled rejection on older…
fix(workerd): end connections without an unhandled rejection on older…
test(workerd): treat a dropped connection's socket error as the known…