Skip to content

async_hooks: destroy emitted more than once for an asyncId #26961

Closed
@Trott

Description

@Trott
  • Version: 12.0.0-pre (current master)
  • Platform: Darwin LIB-0F7FVH8-LT 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64 x86_64
  • Subsystem: async_hooks

This code shows destroy emitting twice for a single asyncId. (You may need to run it more than once to see the error and/or increase the value of N in the code, but it repros most of the time for me.)

'use strict';

const assert = require('assert');
const async_hooks = require('async_hooks');
const http = require('http');

const N = 50;
const KEEP_ALIVE = 100;

const destroyedIds = [];
async_hooks.createHook({
  destroy: (asyncId) => {
    assert(!destroyedIds.includes(asyncId), `${asyncId} already in ${destroyedIds.sort()}`);
    destroyedIds.push(asyncId);
  }
}).enable();

const server = http.createServer(function(req, res) {
  res.end('Hello');
});

const keepAliveAgent = new http.Agent({
  keepAlive: true,
  keepAliveMsecs: KEEP_ALIVE,
});

let M = 0;
server.listen(0, function() {
  for (let i = 0; i < N; ++i) {
    (function makeRequest() {
      http.get({
        port: server.address().port,
        agent: keepAliveAgent
      }, function(res) {
        res.resume();
        M++;
        if (M === N)
          server.close();
        assert.ok(M <= N);
      });
    })();
  }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    async_hooksIssues and PRs related to the async hooks subsystem.confirmed-bugIssues with confirmed bugs.httpIssues or PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions