From 48baf2bfa635753b48e18a712d40942b27367910 Mon Sep 17 00:00:00 2001 From: John Hiesey Date: Wed, 4 Jun 2014 23:33:08 -0700 Subject: [PATCH 1/2] Time out and clean up udp stopped messages This solves one of the problems with the bittorrent-client tests not exiting --- index.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index ce50c9c..33764b1 100644 --- a/index.js +++ b/index.js @@ -172,15 +172,16 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) { var socket = dgram.createSocket('udp4') var transactionId = new Buffer(hat(32), 'hex') - if (opts.event !== '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 () { - timeout = null - cleanup() + var stopped = opts.event === 'stopped' + // if we're sending a stopped message, we don't really care if it arrives, so set + // a short timer and don't call error + var timeout = setTimeout(function () { + timeout = null + cleanup() + if (!stopped) { error('tracker request timed out') - }, 15000) - } + } + }, stopped ? 1500 : 15000) if (timeout && timeout.unref) { timeout.unref() From effd911f21f340acc778330bb24a865b5201a896 Mon Sep 17 00:00:00 2001 From: John Hiesey Date: Wed, 4 Jun 2014 23:35:20 -0700 Subject: [PATCH 2/2] Remove semicolons --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 33764b1..e86d666 100644 --- a/index.js +++ b/index.js @@ -265,7 +265,7 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) { function send (message) { if (!parsedUrl.port) { - parsedUrl.port = 80; + parsedUrl.port = 80 } socket.send(message, 0, message.length, parsedUrl.port, parsedUrl.hostname) } @@ -335,7 +335,7 @@ Tracker.prototype._handleResponse = function (requestUrl, data) { var warning = data['warning message'] if (warning) { - self.client.emit('warning', warning); + self.client.emit('warning', warning) } if (requestUrl === self._announceUrl) {