Skip to content

Commit 0ff2c19

Browse files
committed
timeout might not be defined
1 parent 954b3af commit 0ff2c19

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) {
181181
}, 15000)
182182
}
183183

184-
if (timeout.unref) {
184+
if (timeout && timeout.unref) {
185185
timeout.unref()
186186
}
187187

@@ -236,7 +236,10 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) {
236236
self.client.emit('peer', addr)
237237
})
238238

239-
clearTimeout(timeout)
239+
if (timeout) {
240+
clearTimeout(timeout)
241+
timeout = null
242+
}
240243
try { socket.close() } catch (err) {}
241244
return
242245

@@ -252,7 +255,10 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) {
252255
incomplete: msg.readUInt32BE(16)
253256
})
254257

255-
clearTimeout(timeout)
258+
if (timeout) {
259+
clearTimeout(timeout)
260+
timeout = null
261+
}
256262
try { socket.close() } catch (err) {}
257263
return
258264

@@ -263,7 +269,10 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) {
263269

264270
self.client.emit('error', new Error(msg.slice(8).toString()))
265271

266-
clearTimeout(timeout)
272+
if (timeout) {
273+
clearTimeout(timeout)
274+
timeout = null
275+
}
267276
try { socket.close() } catch (err) {}
268277
return
269278
}
@@ -278,8 +287,11 @@ Tracker.prototype._requestUdp = function (requestUrl, opts) {
278287

279288
function error (message) {
280289
self.client.emit('error', new Error(message + ' (connecting to tracker ' + requestUrl + ')'))
290+
if (timeout) {
291+
clearTimeout(timeout)
292+
timeout = null
293+
}
281294
try { socket.close() } catch (err) { }
282-
clearTimeout(timeout)
283295
}
284296

285297
function genTransactionId () {

0 commit comments

Comments
 (0)