Skip to content

Commit 8aebeb7

Browse files
committed
Merge pull request webtorrent#23 from jhiesey/master
Time out and clean up udp stopped messages
2 parents 575f28e + effd911 commit 8aebeb7

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

index.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,16 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) {
172172
var socket = dgram.createSocket('udp4')
173173
var transactionId = new Buffer(hat(32), 'hex')
174174

175-
if (opts.event !== 'stopped') {
176-
// if we're sending a stopped message, we don't really care if it arrives, so don't
177-
// set a timer
178-
var timeout = setTimeout(function () {
179-
timeout = null
180-
cleanup()
175+
var stopped = opts.event === 'stopped'
176+
// if we're sending a stopped message, we don't really care if it arrives, so set
177+
// a short timer and don't call error
178+
var timeout = setTimeout(function () {
179+
timeout = null
180+
cleanup()
181+
if (!stopped) {
181182
error('tracker request timed out')
182-
}, 15000)
183-
}
183+
}
184+
}, stopped ? 1500 : 15000)
184185

185186
if (timeout && timeout.unref) {
186187
timeout.unref()
@@ -264,7 +265,7 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) {
264265

265266
function send (message) {
266267
if (!parsedUrl.port) {
267-
parsedUrl.port = 80;
268+
parsedUrl.port = 80
268269
}
269270
socket.send(message, 0, message.length, parsedUrl.port, parsedUrl.hostname)
270271
}
@@ -334,7 +335,7 @@ Tracker.prototype._handleResponse = function (requestUrl, data) {
334335

335336
var warning = data['warning message']
336337
if (warning) {
337-
self.client.emit('warning', warning);
338+
self.client.emit('warning', warning)
338339
}
339340

340341
if (requestUrl === self._announceUrl) {

0 commit comments

Comments
 (0)