Skip to content

Commit

Permalink
dgram: 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 6ac8bdc commit 207e48c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ function afterSend(err) {


Socket.prototype.close = function(callback) {
if (callback)
if (typeof callback === 'function')
this.on('close', callback);
this._healthCheck();
this._stopReceiving();
Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-dgram-close-is-not-callback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var assert = require('assert');
var common = require('../common');
var dgram = require('dgram');

var buf = new Buffer(1024);
buf.fill(42);

var socket = dgram.createSocket('udp4');
var closeEvents = 0;
socket.send(buf, 0, buf.length, common.PORT, 'localhost');

// if close callback is not function, ignore the argument.
socket.close('bad argument');

socket.on('close', function() {
++closeEvents;
});

process.on('exit', function() {
assert.equal(closeEvents, 1);
});

0 comments on commit 207e48c

Please sign in to comment.