Skip to content

Commit 5362bef

Browse files
addaleaxjohanneswuerbach
authored andcommitted
async_hooks: fix resource stack for deep stacks
460c81d introduced a bug where the execution resource was not stored properly if we needed to call into C++ to extend the stack size. Fix that bug by always storing the resource. Refs: nodejs/node#34319 Fixes: nodejs/node#34556 PR-URL: nodejs/node#34573 Reviewed-By: Andrey Pechkurov <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Gerhard Stöbich <[email protected]> Reviewed-By: Gus Caplan <[email protected]>
1 parent c9bd1a7 commit 5362bef

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/internal/async_hooks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,11 @@ function hasAsyncIdStack() {
431431
// This is the equivalent of the native push_async_ids() call.
432432
function pushAsyncContext(asyncId, triggerAsyncId, resource) {
433433
const offset = async_hook_fields[kStackLength];
434+
execution_async_resources[offset] = resource;
434435
if (offset * 2 >= async_wrap.async_ids_stack.length)
435436
return pushAsyncContext_(asyncId, triggerAsyncId, resource);
436437
async_wrap.async_ids_stack[offset * 2] = async_id_fields[kExecutionAsyncId];
437438
async_wrap.async_ids_stack[offset * 2 + 1] = async_id_fields[kTriggerAsyncId];
438-
execution_async_resources[offset] = resource;
439439
async_hook_fields[kStackLength]++;
440440
async_id_fields[kExecutionAsyncId] = asyncId;
441441
async_id_fields[kTriggerAsyncId] = triggerAsyncId;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
'use strict';
2+
const common = require('../common');
3+
const { AsyncLocalStorage } = require('async_hooks');
4+
5+
// Regression test for: https://github.com/nodejs/node/issues/34556
6+
7+
const als = new AsyncLocalStorage();
8+
9+
const done = common.mustCall();
10+
11+
function run(count) {
12+
if (count !== 0) return als.run({}, run, --count);
13+
done();
14+
}
15+
run(1000);

0 commit comments

Comments
 (0)