From b68cc5cdde704d964883d7e5f4575a6bead95203 Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Sun, 25 Jun 2017 20:45:48 -0400 Subject: [PATCH 1/4] async-hooks,net: ensure asyncId=null if no handle If the .listen() hasn't been called on the server, there is no handle object. In this case use null as the triggerAsyncId. Fixes: https://github.com/nodejs/node/issues/13548 --- lib/net.js | 3 ++- test/async-hooks/test-get-connections.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/async-hooks/test-get-connections.js diff --git a/lib/net.js b/lib/net.js index 5f4eec89ec87b9..5129a596421e1c 100644 --- a/lib/net.js +++ b/lib/net.js @@ -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) { diff --git a/test/async-hooks/test-get-connections.js b/test/async-hooks/test-get-connections.js new file mode 100644 index 00000000000000..16925536ef5c43 --- /dev/null +++ b/test/async-hooks/test-get-connections.js @@ -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"); +} From bbdc7c1c6d4bd7302324d3d984b727381d8d8aa2 Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Mon, 26 Jun 2017 21:44:31 -0400 Subject: [PATCH 2/4] [squash] Address PR requests --- test/async-hooks/test-get-connections.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/async-hooks/test-get-connections.js b/test/async-hooks/test-get-connections.js index 16925536ef5c43..c5797787395338 100644 --- a/test/async-hooks/test-get-connections.js +++ b/test/async-hooks/test-get-connections.js @@ -1,14 +1,14 @@ 'use strict'; +const common = require('../common'); 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"); -} +/* This test was based on an error raised by Haraka. + It caused server.getConnections to raise an exception. + + See: https://github.com/haraka/Haraka/pull/1951 +*/ + +server.getConnections(common.mustCall()); From fc5a7fc1a5144240837fd79af24bbced0bb3a02f Mon Sep 17 00:00:00 2001 From: Matt Sergeant Date: Mon, 26 Jun 2017 21:53:46 -0400 Subject: [PATCH 3/4] [squash] More cleanups from PR comments --- test/async-hooks/test-get-connections.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/async-hooks/test-get-connections.js b/test/async-hooks/test-get-connections.js index c5797787395338..56e1c5f38b3dcc 100644 --- a/test/async-hooks/test-get-connections.js +++ b/test/async-hooks/test-get-connections.js @@ -1,14 +1,11 @@ 'use strict'; const common = require('../common'); -const assert = require('assert'); const net = require('net'); const server = net.createServer(); -/* This test was based on an error raised by Haraka. - It caused server.getConnections to raise an exception. - - See: https://github.com/haraka/Haraka/pull/1951 -*/ +// This test was based on an error raised by Haraka. +// It caused server.getConnections to raise an exception. +// Ref: https://github.com/haraka/Haraka/pull/1951 server.getConnections(common.mustCall()); From 6ccf034dbc280c9fe7a6a63475c693243ff082ad Mon Sep 17 00:00:00 2001 From: Andreas Madsen Date: Mon, 3 Jul 2017 13:59:08 +0200 Subject: [PATCH 4/4] [squash] rename test --- .../{test-get-connections.js => test-net-get-connections.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/async-hooks/{test-get-connections.js => test-net-get-connections.js} (100%) diff --git a/test/async-hooks/test-get-connections.js b/test/async-hooks/test-net-get-connections.js similarity index 100% rename from test/async-hooks/test-get-connections.js rename to test/async-hooks/test-net-get-connections.js