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: #34319
Fixes: #34556

PR-URL: #34573
Reviewed-By: Andrey Pechkurov <apechkurov@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: Gus Caplan <me@gus.host>
  • Loading branch information
addaleax committed Sep 22, 2020
1 parent a2141d3 commit cfc769b
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 @@ -434,11 +434,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);
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 cfc769b

Please sign in to comment.