-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Description
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
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