From 351f829104d218d4d5e125dbcd1354e42e94a407 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Fri, 23 May 2014 20:34:46 -0700 Subject: [PATCH] udp client: don't set a timer for stopped message --- index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index ca8a0e2..36ebd8c 100644 --- a/index.js +++ b/index.js @@ -170,11 +170,17 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) { var socket = dgram.createSocket('udp4') var transactionId = new Buffer(hat(32), 'hex') - var timeout = setTimeout(function () { - error('tracker request timed out') - }, 15000) socket.unref() + if (opts.event !== EVENTS.stopped) { + // if we're sending a stopped message, we don't really care if it arrives, so don't + // set a timer + var timeout = setTimeout(function () { + try { socket.close() } catch (err) {} + error('tracker request timed out') + }, 15000) + } + if (timeout.unref) { timeout.unref() }