Skip to content

Commit

Permalink
async_hooks: fix resource stack for deep stacks
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
addaleax authored and johanneswuerbach committed Sep 21, 2020
1 parent c9bd1a7 commit 5362bef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,11 +431,11 @@ function hasAsyncIdStack() {
// This is the equivalent of the native push_async_ids() call.
function pushAsyncContext(asyncId, triggerAsyncId, resource) {
const offset = async_hook_fields[kStackLength];
execution_async_resources[offset] = resource;
if (offset * 2 >= async_wrap.async_ids_stack.length)
return pushAsyncContext_(asyncId, triggerAsyncId, resource);
async_wrap.async_ids_stack[offset * 2] = async_id_fields[kExecutionAsyncId];
async_wrap.async_ids_stack[offset * 2 + 1] = async_id_fields[kTriggerAsyncId];
execution_async_resources[offset] = resource;
async_hook_fields[kStackLength]++;
async_id_fields[kExecutionAsyncId] = asyncId;
async_id_fields[kTriggerAsyncId] = triggerAsyncId;
Expand Down
15 changes: 15 additions & 0 deletions test/parallel/test-async-local-storage-deep-stack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';
const common = require('../common');
const { AsyncLocalStorage } = require('async_hooks');

// Regression test for: https://github.com/nodejs/node/issues/34556

const als = new AsyncLocalStorage();

const done = common.mustCall();

function run(count) {
if (count !== 0) return als.run({}, run, --count);
done();
}
run(1000);

0 comments on commit 5362bef

Please sign in to comment.