Skip to content

Commit 48baf2b

Browse files
committed
Time out and clean up udp stopped messages
This solves one of the problems with the bittorrent-client tests not exiting
1 parent 575f28e commit 48baf2b

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

index.js

Lines changed: 9 additions & 8 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()

0 commit comments

Comments
 (0)