Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

net: ignore socket.setTimeout(Infinity) (and NaN)

  • Loading branch information...
commit b0950cbea282024a21c735ba20803ac8b05e0b48 1 parent 3c99894
@indutny indutny authored
Showing with 21 additions and 15 deletions.
  1. +1 −1  lib/net.js
  2. +20 −14 test/simple/test-net-settimeout.js
View
2  lib/net.js
@@ -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) {
View
34 test/simple/test-net-settimeout.js
@@ -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 b0950cb

Please sign in to comment.
Something went wrong with that request. Please try again.