Skip to content

Commit 5aed83c

Browse files
addaleaxcodebytere
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: #34319 Fixes: #34556 PR-URL: #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 9ed424f commit 5aed83c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/internal/async_hooks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,11 @@ function hasAsyncIdStack() {
499499
// This is the equivalent of the native push_async_ids() call.
500500
function pushAsyncContext(asyncId, triggerAsyncId, resource) {
501501
const offset = async_hook_fields[kStackLength];
502+
execution_async_resources[offset] = resource;
502503
if (offset * 2 >= async_wrap.async_ids_stack.length)
503504
return pushAsyncContext_(asyncId, triggerAsyncId);
504505
async_wrap.async_ids_stack[offset * 2] = async_id_fields[kExecutionAsyncId];
505506
async_wrap.async_ids_stack[offset * 2 + 1] = async_id_fields[kTriggerAsyncId];
506-
execution_async_resources[offset] = resource;
507507
async_hook_fields[kStackLength]++;
508508
async_id_fields[kExecutionAsyncId] = asyncId;
509509
async_id_fields[kTriggerAsyncId] = triggerAsyncId;
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)