From 474d865d9f71bcb6e75ed1f2e58478842e371e5a Mon Sep 17 00:00:00 2001 From: achingbrain Date: Fri, 26 Nov 2021 17:06:22 +0000 Subject: [PATCH] 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 --- src/connection-manager/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/connection-manager/index.js b/src/connection-manager/index.js index 802c9fe6..331b9ad9 100644 --- a/src/connection-manager/index.js +++ b/src/connection-manager/index.js @@ -340,22 +340,22 @@ class ConnectionManager extends EventEmitter { 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)) { log('connecting to a peerStore stored peer %s', peers[i].id.toB58String()) try { await this._libp2p.dialer.connectToPeer(peers[i].id) - - // Connection Manager was stopped - if (!this._started) { - return - } } catch (/** @type {any} */ 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) }