Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
net: ignore socket.setTimeout(Infinity) (and NaN)
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny committed Jul 19, 2012
1 parent d9057cc commit 1fa0bca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/net.js
Expand Up @@ -160,7 +160,7 @@ Socket.prototype.listen = function() {


Socket.prototype.setTimeout = function(msecs, callback) {
if (msecs > 0) {
if (msecs > 0 && !isNaN(msecs) && isFinite(msecs)) {
timers.enroll(this, msecs);
timers.active(this);
if (callback) {
Expand Down
34 changes: 20 additions & 14 deletions test/simple/test-net-settimeout.js
Expand Up @@ -33,18 +33,24 @@ var server = net.createServer(function(c) {
});
server.listen(common.PORT);

var socket = net.createConnection(common.PORT, 'localhost');

socket.setTimeout(T, function() {
socket.destroy();
server.close();
assert.ok(false);
var killers = [0, Infinity, NaN];

var left = killers.length;
killers.forEach(function(killer) {
var socket = net.createConnection(common.PORT, 'localhost');

socket.setTimeout(T, function() {
socket.destroy();
if (--left === 0) server.close();
assert.ok(killer !== 0);
clearTimeout(timeout);
});

socket.setTimeout(killer);

var timeout = setTimeout(function() {
socket.destroy();
if (--left === 0) server.close();
assert.ok(killer === 0);
}, T * 2);
});

socket.setTimeout(0);

setTimeout(function() {
socket.destroy();
server.close();
assert.ok(true);
}, T * 2);

0 comments on commit 1fa0bca

Please sign in to comment.