This commit is contained in:
Feross Aboukhadijeh 2020-10-29 10:25:57 -10:00
parent c88bbb4a62
commit 2a828292b8
3 changed files with 9 additions and 3 deletions

View File

@ -81,12 +81,14 @@ class HTTPTracker extends Tracker {
this.destroyed = true
clearInterval(this.interval)
let timeout
// If there are no pending requests, destroy immediately.
if (this.cleanupFns.length === 0) return destroyCleanup()
// Otherwise, wait a short time for pending requests to complete, then force
// destroy them.
let timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT)
timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT)
// But, if all pending requests complete before the timeout fires, do cleanup
// right away.

View File

@ -41,12 +41,14 @@ class UDPTracker extends Tracker {
this.destroyed = true
clearInterval(this.interval)
let timeout
// If there are no pending requests, destroy immediately.
if (this.cleanupFns.length === 0) return destroyCleanup()
// Otherwise, wait a short time for pending requests to complete, then force
// destroy them.
let timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT)
timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT)
// But, if all pending requests complete before the timeout fires, do cleanup
// right away.

View File

@ -129,12 +129,14 @@ class WebSocketTracker extends Tracker {
socket.on('error', noop) // ignore all future errors
socket.once('close', cb)
let timeout
// If there is no data response expected, destroy immediately.
if (!this.expectingResponse) return destroyCleanup()
// Otherwise, wait a short time for potential responses to come in from the
// server, then force close the socket.
let timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT)
timeout = setTimeout(destroyCleanup, common.DESTROY_TIMEOUT)
// But, if a response comes from the server before the timeout fires, do cleanup
// right away.