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
PR-URL: https://github.com/nodejs/node/pull/13938
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
This commit is contained in:
Matt Sergeant 2017-07-05 14:58:02 +02:00 коммит произвёл Andreas Madsen
Родитель 5c6c02996b
Коммит aa8655a0da
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 2FEE61B3C9E40F20
2 изменённых файлов: 13 добавлений и 1 удалений

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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());