diff --git a/lib/timers.js b/lib/timers.js index 5419c03870..272cad95f7 100644 --- a/lib/timers.js +++ b/lib/timers.js @@ -43,7 +43,6 @@ function shift (list) { function remove (item) { item._idleNext._idlePrev = item._idlePrev; item._idlePrev._idleNext = item._idleNext; - item._idleNext = null; } @@ -209,7 +208,7 @@ exports.setTimeout = function (callback, after) { exports.clearTimeout = function (timer) { - if (timer) { + if (timer && (timer.callback || timer._onTimeout)) { timer.callback = timer._onTimeout = null; exports.unenroll(timer); if (timer instanceof Timer) timer.stop(); // for after === 0 diff --git a/test/simple/test-net-can-reset-timeout.js b/test/simple/test-net-can-reset-timeout.js new file mode 100644 index 0000000000..db0d68a4b4 --- /dev/null +++ b/test/simple/test-net-can-reset-timeout.js @@ -0,0 +1,41 @@ +var net = require('net'); +var common = require('../common'); +var assert = require('assert'); + +var timeoutCount = 0; + +var server = net.createServer(function(stream){ + stream.setTimeout(100); + + stream.on('timeout', function () { + console.log("timeout"); + // try to reset the timeout. + stream.write("WHAT."); + // don't worry, the socket didn't *really* time out, we're just thinking + // it did. + timeoutCount += 1; + }); + + stream.on('end', function () { + console.log("server side end"); + stream.end(); + }); +}); + +server.listen(common.PORT, function() { + var c = net.createConnection(common.PORT); + + c.on('data', function () { + c.end(); + }); + + c.on('end', function () { + console.log("client side end"); + server.close(); + }); +}); + + +process.on('exit', function () { + assert.equal(1, timeoutCount); +});