Sitelet https://web.archive.org/web/20220420021002/https://github.com/nodejs/node/commit/cfc769b048
Skip to content
Permalink
Browse files
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 <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 cfc769b04847fde8a3ca13f4d3fcc25cf865a61d
Showing with 16 additions and 1 deletion.
  1. +1 −1 lib/internal/async_hooks.js
  2. +15 −0 test/parallel/test-async-local-storage-deep-stack.js
@@ -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;
@@ -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.