summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2014-05-15 22:48:27 -0400
committerFedor Indutny <fedor@indutny.com>2014-05-18 17:59:52 +0400
commitf1dc55d7018e2669550a8be2c5b6c091da616483 (patch)
tree8297c2e2718c07e3fe322e9d6b16af3398cfd6ba /lib
parent655ec2113aeb1050f26f714b43992c162ec168e2 (diff)
downloadnode-new-f1dc55d7018e2669550a8be2c5b6c091da616483.tar.gz
net: don't throw on net.Server.close()
When close() is called on a non-listening server, a synchronous error is thrown. This commit causes the error to be passed to the asynchronous callback function instead. Signed-off-by: Fedor Indutny <fedor@indutny.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/net.js18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/net.js b/lib/net.js
index 8cc13bc12d..3b4f7da078 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -1341,16 +1341,20 @@ Server.prototype.close = function(cb) {
self._emitCloseIfDrained();
}
- if (!this._handle) {
- // Throw error. Follows net_legacy behaviour.
- throw new Error('Not running');
+ if (cb) {
+ if (!this._handle) {
+ this.once('close', function() {
+ cb(new Error('Not running'));
+ });
+ } else {
+ this.once('close', cb);
+ }
}
- if (cb) {
- this.once('close', cb);
+ if (this._handle) {
+ this._handle.close();
+ this._handle = null;
}
- this._handle.close();
- this._handle = null;
if (this._usingSlaves) {
var self = this,