Skip to content

Commit 351f829

Browse files
committed
udp client: don't set a timer for stopped message
1 parent 6f1aa98 commit 351f829

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,17 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) {
170170
var socket = dgram.createSocket('udp4')
171171
var transactionId = new Buffer(hat(32), 'hex')
172172

173-
var timeout = setTimeout(function () {
174-
error('tracker request timed out')
175-
}, 15000)
176173
socket.unref()
177174

175+
if (opts.event !== EVENTS.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+
try { socket.close() } catch (err) {}
180+
error('tracker request timed out')
181+
}, 15000)
182+
}
183+
178184
if (timeout.unref) {
179185
timeout.unref()
180186
}

0 commit comments

Comments
 (0)