Skip to content

Commit

Permalink
async-hooks,net: ensure asyncId=null if no handle
Browse files Browse the repository at this point in the history
If the .listen() hasn't been called on the server, there is no handle
object. In this case use null as the triggerAsyncId.

Fixes: nodejs#13548
  • Loading branch information
Matt Sergeant authored and AndreasMadsen committed Jul 3, 2017
1 parent f05653d commit b68cc5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,8 @@ Server.prototype.getConnections = function(cb) {
const self = this;

function end(err, connections) {
nextTick(self[async_id_symbol], cb, err, connections);
const asyncId = self._handle ? self[async_id_symbol] : null;
nextTick(asyncId, cb, err, connections);
}

if (!this._usingSlaves) {
Expand Down
14 changes: 14 additions & 0 deletions test/async-hooks/test-get-connections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict';

const assert = require('assert');
const net = require('net');
const server = net.createServer();

try {
server.getConnections(() => {
assert.ok(true, "No error thrown")
});
}
catch (e) {
assert.ok(false, "getConnections threw an error");
}

0 comments on commit b68cc5c

Please sign in to comment.