Node: async hook stack has become corrupted

Created on 25 Jun 2017  ·  7Comments  ·  Source: nodejs/node

About async_hooks and AsyncResource.
I don't know why happend 'Error: async hook stack has become corrupted ', when use emitBefore hook without emitAfter hook.
And i add emitAfter hook, no error.

This's my code:

var asyncHooks = require('async_hooks');
var AsyncResource = asyncHooks.AsyncResource;
var fs = require('fs');

asyncHooks.createHook({
  init(asyncId, type, triggerId, resource) {
    // const cId = asyncHooks.currentId();
    // fs.writeSync(1, `${type}(${asyncId}): trigger: ${triggerId} scope: ${cId} resource: ${resource}\n`);
  },
  before(asyncId) {
    fs.writeSync(1, `before: ${asyncId}\n`);
  }
}).enable();

class Test extends AsyncResource{
    constructor(){
        super('Test');
    }
    test (){
        this.emitBefore();
        console.log(1);
        console.log(2);
        // this.emitAfter();  // 不去emitAfter,会发生错误:Error: async hook stack has become corrupted (actual: 2, expected: 1)
    }
}

new Test().test();
env:
node v8.1.0
async_hooks question

Most helpful comment

For every emitBefore there MUST be a corresponding emitAfter in order for async_hooks to work. What is your use case for emitBefore without emitAfter?

All 7 comments

/cc @nodejs/async_hooks

For every emitBefore there MUST be a corresponding emitAfter in order for async_hooks to work. What is your use case for emitBefore without emitAfter?

maybe

@chow-xiang Is this still an issue?

any update to this?

We change the API, this error for this exact reason can no longer happen.

Got it thanks!

On Sun, May 31, 2020, 1:27 AM Andreas Madsen notifications@github.com
wrote:

We change the API, this error for this exact reason can no longer happen.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/nodejs/node/issues/13906#issuecomment-636439594, or
unsubscribe
https://github.com/notifications/unsubscribe-auth/AFYTD5EMBBRCERVX43AEJKDRUIIIPANCNFSM4DQSDZQA
.

Was this page helpful?
0 / 5 - 0 ratings