diff --git a/lib/net.js b/lib/net.js index 1cd8b6da352..af8c3dd8feb 100644 --- a/lib/net.js +++ b/lib/net.js @@ -1368,7 +1368,7 @@ Server.prototype.close = function(cb) { self._emitCloseIfDrained(); } - if (cb) { + if (typeof cb === 'function') { if (!this._handle) { this.once('close', function() { cb(new Error('Not running')); diff --git a/test/parallel/test-net-listen-close-server-callback-is-not-function.js b/test/parallel/test-net-listen-close-server-callback-is-not-function.js new file mode 100644 index 00000000000..f4eff779406 --- /dev/null +++ b/test/parallel/test-net-listen-close-server-callback-is-not-function.js @@ -0,0 +1,20 @@ +var assert = require('assert'); +var common = require('../common'); +var net = require('net'); + +var server = net.createServer(assert.fail); +var closeEvents = 0; + +server.on('close', function() { + ++closeEvents; +}); + +server.listen(common.PORT, function() { + assert(false); +}); + +server.close('bad argument'); + +process.on('exit', function() { + assert.equal(closeEvents, 1); +});