Skip to content

AsyncWrap: TCPWrap created before MakeCallback #2986

@AndreasMadsen

Description

@AndreasMadsen

When creating a TCP server, the TCP handles there holds the socket is created in C++ land. The socket handle is then send to the onconnection server handle event using MakeCallback.

code link: https://github.com/nodejs/node/blob/master/src/tcp_wrap.cc#L259L272

Because the socket handle is created before MakeCallback, the async_hooks_init_function for the socket handle is called before async_hooks_before_function for the server handle. This makes it impossible to trace back the origin of the socket handle.

dprof dump: http://bl.ocks.org/AndreasMadsen/raw/da3adb776bdfcf30f97f/ - Notice the free hanging blue line, which has an origin from nowhere.

edit: the link is only tested in Chrome, so here is a picture
skaermbillede 2015-09-22 kl 20 23 43

The visualization/test was done with the following code:

'use strict';
require('../../dprof.js');

const net = require('net');

const server = net.createServer(function (socket) {
  socket.end('hallo world');
});

server.listen(0, 'localhost', function () {
  const addr = server.address();
  const socket = net.connect(addr.port, addr.host, function () {
    socket.once('readable', function () {
      socket.read();
      socket.once('readable', server.close.bind(server));
    });
  });
});

This issue appears to be caused by 7dde95a8bd. I agree that is is wired to call async_hooks_before_function in the AsyncWrap constructor, particularly in this case because it suggests that the creation of the TCPWrap object and onconnection happens in two different async turns.

However I'm not sure what the proper fix would be.

/cc @trevnorris

Metadata

Metadata

Assignees

Labels

c++Issues and PRs that require attention from people who are familiar with C++.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions