diff --git a/lib/net_uv.js b/lib/net_uv.js index 354b986045..2c9df4b739 100644 --- a/lib/net_uv.js +++ b/lib/net_uv.js @@ -631,10 +631,13 @@ function onconnection(clientHandle) { Server.prototype.close = function() { - if (this._handle != null) { - this._handle.close(); - this._handle = null; + if (!this._handle) { + // Throw error. Follows net_legacy behaviour. + throw new Error('Not running'); } + + this._handle.close(); + this._handle = null; this.emit('close'); }; diff --git a/test/simple/test-http-unix-socket.js b/test/simple/test-http-unix-socket.js index 2a002332f5..857ef6e32b 100644 --- a/test/simple/test-http-unix-socket.js +++ b/test/simple/test-http-unix-socket.js @@ -75,8 +75,12 @@ server.listen(common.PIPE, function() { }); process.on('exit', function() { - server.close(); assert.ok(status_ok); assert.ok(headers_ok); assert.ok(body_ok); + + // Double close should throw. Follows net_legacy behaviour. + assert.throws(function() { + server.close(); + }); });