From 984dc057e39b09443cb31345b256b596509a588d Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 22 Jul 2011 01:23:50 +0200 Subject: [PATCH] net_uv: throw if Server.prototype.close() is called twice Follows net_legacy behaviour. --- lib/net_uv.js | 9 ++++++--- test/simple/test-http-unix-socket.js | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) 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(); + }); });