mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-12 16:51:23 +00:00
fix: clean up pending dial targets (#1059)
If the `Promise.race` throws, execution of the function is terminated so the pending dial target is never removed from the map and we leak memory. This can happen when there are invalid multiaddrs or when a peer reports more dialable addresses than the threshold. Instead wrap the `Promise.race` in a `try/finally` which will always remove the pending dial target in the event of success or failure.
This commit is contained in:
@ -155,14 +155,16 @@ class Dialer {
|
|||||||
this._pendingDialTargets.set(id, { resolve, reject })
|
this._pendingDialTargets.set(id, { resolve, reject })
|
||||||
})
|
})
|
||||||
|
|
||||||
const dialTarget = await Promise.race([
|
try {
|
||||||
this._createDialTarget(peer),
|
const dialTarget = await Promise.race([
|
||||||
cancellablePromise
|
this._createDialTarget(peer),
|
||||||
])
|
cancellablePromise
|
||||||
|
])
|
||||||
|
|
||||||
this._pendingDialTargets.delete(id)
|
return dialTarget
|
||||||
|
} finally {
|
||||||
return dialTarget
|
this._pendingDialTargets.delete(id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user