Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5d75ba4
test: remove async_wrap tests
trevnorris Oct 31, 2016
53a85f1
stream_base,tls_wrap: notify on destruct
trevnorris Oct 31, 2016
757ac35
crypto: use named FunctionTemplate
trevnorris Sep 28, 2016
29e9d09
async_wrap: use more specific providers
trevnorris Nov 2, 2016
82d8606
async_wrap: use double, not int64_t, for uid
trevnorris Dec 13, 2016
4a427e3
async_wrap: add GetAsyncId() method
trevnorris Nov 2, 2016
f5d6056
src: add AsyncWrap::GetAsyncId() to all children
trevnorris Sep 28, 2016
1c9154c
async_wrap: only call SetupHooks() once
trevnorris Nov 2, 2016
4c809dd
async_hooks: introduce async_hooks.js
trevnorris Nov 2, 2016
3611f6a
async_hooks: check correct array
trevnorris Nov 17, 2016
d244d55
next_tick: add async_hooks support
trevnorris Nov 14, 2016
977718e
timers: initial timers support
trevnorris Nov 16, 2016
3e5ef64
fs: add initial async_hooks support
trevnorris Nov 17, 2016
955d390
net: add initial async_hooks net support
trevnorris Nov 16, 2016
da7c67c
lib: add triggerId support to various modules
trevnorris Nov 17, 2016
b3721ba
http: reset Agents on free pool
trevnorris Nov 17, 2016
78a2a7f
src: properly propagate triggerId in more places
trevnorris Nov 17, 2016
eab9e86
timers: manually set ids if no hooks exist
trevnorris Nov 18, 2016
4399547
fs: add AsyncReset to TSLWrap
trevnorris Nov 22, 2016
830428a
async_hooks: allow enable/disable while processing
trevnorris Dec 15, 2016
ad382c5
async_hooks: run after() in case of exception
trevnorris Dec 20, 2016
6e5af4a
streams: set initTriggerId before nextTick()
trevnorris Dec 20, 2016
32b5288
next_tick: set MicrotaskCallback to the void
trevnorris Dec 20, 2016
bd660a4
test: allow running with async_hook noops
trevnorris Dec 20, 2016
e8c27f8
async_hooks: move location of restoreTmpHooks()
trevnorris Dec 22, 2016
0ab9547
async_wrap: use v8::Eternal for provider strings
trevnorris Dec 27, 2016
352c89a
fs: use preallocated Float64Array
trevnorris Dec 29, 2016
e9ae576
PARTIAL remove all applicable TODOs
trevnorris Jan 3, 2017
015e665
async_hooks: verify stack integrity
trevnorris Jan 11, 2017
e2af82f
async_hooks: place destroy ids on native list
trevnorris Jan 17, 2017
1b7438f
test: add more async hook tests
trevnorris Jan 17, 2017
ca8d6db
timers: don't reset _asyncId/_triggerId
trevnorris Jan 17, 2017
ac2e137
async_hooks: return early if emitting the void
trevnorris Jan 17, 2017
da138cf
async_hooks: really always exit on exception
trevnorris Jan 18, 2017
25dd8af
async_wrap: don't allow exports to be overwritten
trevnorris Jan 18, 2017
2d98170
fix bug in array buffer size in fs
trevnorris Jan 20, 2017
7bc7d3c
PARTIAL implement new stack tracker
trevnorris Jan 20, 2017
edf67a7
timers: don't emit destroy() on same id twice
trevnorris Jan 26, 2017
90f0a63
test: make async hooks test better
trevnorris Jan 26, 2017
1ff2dfb
async_wrap: print msg on error instead of abort
trevnorris Feb 1, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
net: add initial async_hooks net support
cluster is still slightly messed up, as I figure out how to handle the
"faux" handles passed to net.
  • Loading branch information
trevnorris committed Jan 27, 2017
commit 955d390734535a4e81d02117b64fc4853b97e7da
8 changes: 7 additions & 1 deletion lib/internal/cluster/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,13 @@ function rr(message, indexesKey, cb) {
// with it. Fools net.Server into thinking that it's backed by a real
// handle. Use a noop function for ref() and unref() because the control
// channel is going to keep the worker alive anyway.
const handle = { close, listen, ref: noop, unref: noop };
//
// Emulate AsyncWrap::GetAsyncId() by returning a value from getAsyncId().
// TODO(trevnorris): Right now just return -2 so locations where this is
// propagating can be identified, if there are any. Since this is a faux
// handle not sure how to treat it (i.e. should it receive its own uid?).
const handle = {
close, listen, ref: noop, unref: noop, getAsyncId: () => -2 };

if (message.sockname) {
handle.getsockname = getsockname; // TCP handles only.
Expand Down
6 changes: 4 additions & 2 deletions lib/internal/cluster/shared_handle.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ function SharedHandle(key, address, port, addressType, fd, flags) {
else
rval = net._createServerHandle(address, port, addressType, fd);

if (typeof rval === 'number')
if (typeof rval === 'number') {
this.errno = rval;
else
} else {
this.handle = rval;
this.getAsyncId = this.handle.getAsyncId;
}
}

SharedHandle.prototype.add = function(worker, send) {
Expand Down
20 changes: 20 additions & 0 deletions lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const PipeConnectWrap = process.binding('pipe_wrap').PipeConnectWrap;
const ShutdownWrap = process.binding('stream_wrap').ShutdownWrap;
const WriteWrap = process.binding('stream_wrap').WriteWrap;

const setInitTriggerId = require('async_hooks').setInitTriggerId;

var cluster;
const errnoException = util._errnoException;
Expand Down Expand Up @@ -114,6 +115,7 @@ function initSocketHandle(self) {
if (self._handle) {
self._handle.owner = self;
self._handle.onread = onread;
self._asyncId = self._handle.getAsyncId();

// If handle doesn't support writev - neither do we
if (!self._handle.writev)
Expand All @@ -129,6 +131,7 @@ function Socket(options) {
if (!(this instanceof Socket)) return new Socket(options);

this.connecting = false;
this._asyncId = -1;
this._hadError = false;
this._handle = null;
this._parent = null;
Expand All @@ -143,9 +146,11 @@ function Socket(options) {

if (options.handle) {
this._handle = options.handle; // private
this._asyncId = this._handle.getAsyncId();
} else if (options.fd !== undefined) {
this._handle = createHandle(options.fd);
this._handle.open(options.fd);
this._asyncId = this._handle.getAsyncId();
if ((options.fd == 1 || options.fd == 2) &&
(this._handle instanceof Pipe) &&
process.platform === 'win32') {
Expand Down Expand Up @@ -228,6 +233,7 @@ function onSocketFinish() {
if (!this._handle || !this._handle.shutdown)
return this.destroy();

setInitTriggerId(this._asyncId);
var req = new ShutdownWrap();
req.oncomplete = afterShutdown;
req.handle = this._handle;
Expand Down Expand Up @@ -296,6 +302,7 @@ function writeAfterFIN(chunk, encoding, cb) {
// TODO: defer error events consistently everywhere, not just the cb
this.emit('error', er);
if (typeof cb === 'function') {
setInitTriggerId(this._asyncId);
process.nextTick(cb, er);
}
}
Expand Down Expand Up @@ -854,6 +861,7 @@ function connect(self, address, port, addressType, localAddress, localPort) {
}

if (addressType === 6 || addressType === 4) {
setInitTriggerId(self._asyncId);
const req = new TCPConnectWrap();
req.oncomplete = afterConnect;
req.address = address;
Expand All @@ -867,6 +875,7 @@ function connect(self, address, port, addressType, localAddress, localPort) {
err = self._handle.connect6(req, address, port);

} else {
setInitTriggerId(self._asyncId);
const req = new PipeConnectWrap();
req.address = address;
req.oncomplete = afterConnect;
Expand Down Expand Up @@ -968,6 +977,7 @@ function lookupAndConnect(self, options) {
// If host is an IP, skip performing a lookup
var addressType = exports.isIP(host);
if (addressType) {
setInitTriggerId(self._asyncId);
process.nextTick(function() {
if (self.connecting)
connect(self, host, port, addressType, localAddress, localPort);
Expand Down Expand Up @@ -1061,6 +1071,7 @@ function afterConnect(status, handle, req, readable, writable) {

// Update handle if it was wrapped
// TODO(indutny): assert that the handle is actually an ancestor of old one
// TODO(trevnorris): Doesn't look like this does anything. Verify and remove.
handle = self._handle;

debug('afterConnect');
Expand Down Expand Up @@ -1137,6 +1148,7 @@ function Server(options, connectionListener) {
configurable: true, enumerable: false
});

this._asyncId = -1;
this._handle = null;
this._usingSlaves = false;
this._slaves = [];
Expand Down Expand Up @@ -1252,6 +1264,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
this._handle = rval;
}

this._asyncId = this._handle.getAsyncId();
this._handle.onconnection = onconnection;
this._handle.owner = this;

Expand All @@ -1261,6 +1274,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
var ex = exceptionWithHostPort(err, 'listen', address, port);
this._handle.close();
this._handle = null;
setInitTriggerId(this._asyncId);
process.nextTick(emitErrorNT, this, ex);
return;
}
Expand All @@ -1272,6 +1286,7 @@ Server.prototype._listen2 = function(address, port, addressType, backlog, fd) {
if (this._unref)
this.unref();

setInitTriggerId(this._asyncId);
process.nextTick(emitListeningNT, this);
};

Expand Down Expand Up @@ -1357,6 +1372,7 @@ Server.prototype.listen = function() {

if (options instanceof TCP) {
this._handle = options;
this._asyncId = this._handle.getAsyncId();
listen(this, null, -1, -1, backlog);
} else if (typeof options.fd === 'number' && options.fd >= 0) {
listen(this, null, null, null, backlog, options.fd);
Expand Down Expand Up @@ -1455,7 +1471,10 @@ function onconnection(err, clientHandle) {


Server.prototype.getConnections = function(cb) {
const self = this;

function end(err, connections) {
setInitTriggerId(self._asyncId);
process.nextTick(cb, err, connections);
}

Expand Down Expand Up @@ -1534,6 +1553,7 @@ Server.prototype._emitCloseIfDrained = function() {
return;
}

setInitTriggerId(this._asyncId);
process.nextTick(emitCloseNT, this);
};

Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-net-end-close.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const s = new net.Socket({
readStart: function() {
process.nextTick(() => this.onread(uv.UV_EOF, null));
},
close: (cb) => process.nextTick(cb)
close: (cb) => process.nextTick(cb),
getAsyncId: () => 0,
},
writable: false
});
Expand Down