diff --git a/lib/net.js b/lib/net.js index 5f4eec89ec..5129a59642 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-net-get-connections.js b/test/async-hooks/test-net-get-connections.js new file mode 100644 index 0000000000..56e1c5f38b --- /dev/null +++ b/test/async-hooks/test-net-get-connections.js @@ -0,0 +1,11 @@ +'use strict'; + +const common = require('../common'); +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. +// Ref: https://github.com/haraka/Haraka/pull/1951 + +server.getConnections(common.mustCall());