mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 10:32:14 +00:00
fix: do not auto-dial after shut down
The `await` in the auto-connect loop means we can start a dial after shutdown but before we test to see if we should break out of the loop. Instead, use the `this._started` property to break out of the loop, then test again to see if we should use retimer to schedule a further auto-dial attempt. Fixes: https://github.com/ipfs/js-ipfs/issues/3923
This commit is contained in:
parent
eacd7e8f76
commit
474d865d9f
@ -340,22 +340,22 @@ class ConnectionManager extends EventEmitter {
|
|||||||
return -1
|
return -1
|
||||||
})
|
})
|
||||||
|
|
||||||
for (let i = 0; i < peers.length && this.size < minConnections; i++) {
|
for (let i = 0; i < peers.length && this.size < minConnections && this._started; i++) {
|
||||||
if (!this.get(peers[i].id)) {
|
if (!this.get(peers[i].id)) {
|
||||||
log('connecting to a peerStore stored peer %s', peers[i].id.toB58String())
|
log('connecting to a peerStore stored peer %s', peers[i].id.toB58String())
|
||||||
try {
|
try {
|
||||||
await this._libp2p.dialer.connectToPeer(peers[i].id)
|
await this._libp2p.dialer.connectToPeer(peers[i].id)
|
||||||
|
|
||||||
// Connection Manager was stopped
|
|
||||||
if (!this._started) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} catch (/** @type {any} */ err) {
|
} catch (/** @type {any} */ err) {
|
||||||
log.error('could not connect to peerStore stored peer', err)
|
log.error('could not connect to peerStore stored peer', err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Connection Manager was stopped
|
||||||
|
if (!this._started) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this._autoDialTimeout = retimer(this._autoDial, this._options.autoDialInterval)
|
this._autoDialTimeout = retimer(this._autoDial, this._options.autoDialInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user