Skip to content

Commit

Permalink
net: check close callback is function
Browse files Browse the repository at this point in the history
PR-URL: #609
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
  • Loading branch information
yosuke-furukawa authored and bnoordhuis committed Feb 2, 2015
1 parent 207e48c commit 8c0742f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 8c0742f

Please sign in to comment.