Skip to content

Commit ba4681b

Browse files
Alan Shawjacobheun
Alan Shaw
authored andcommitted
fix: conn mngr min/max connection values (#528)
Fixes the case when options are passed with `maxConnections` and/or `minConnections` set to `undefined`: ```console { defaultOptions: { maxConnections: Infinity, minConnections: 0, maxData: Infinity, maxSentData: Infinity, maxReceivedData: Infinity, maxEventLoopDelay: Infinity, pollInterval: 2000, movingAverageInterval: 60000, defaultPeerValue: 1 }, options: { minPeers: 25, maxConnections: undefined, minConnections: undefined } } { maxConnections: undefined, minConnections: undefined } 1) "before all" hook in "custom config" (node:67176) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Connection Manager maxConnections must be greater than minConnections at new ConnectionManager (node_modules/libp2p/src/connection-manager/index.js:43:5) at new Libp2p (node_modules/libp2p/src/index.js:92:30) at Object.module.exports [as libp2p] (src/core/components/libp2p.js:27:10) at Proxy.start (src/core/components/start.js:48:31) at async Daemon.start (src/cli/daemon.js:63:31) at async startHttpAPI (test/http-api/routes.js:29:5) at async Context.<anonymous> (test/http-api/routes.js:48:7) ```
1 parent 6b00eea commit ba4681b

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"libp2p-crypto": "^0.17.1",
6060
"libp2p-interfaces": "^0.1.5",
6161
"mafmt": "^7.0.0",
62-
"merge-options": "^1.0.1",
62+
"merge-options": "^2.0.0",
6363
"moving-average": "^1.0.0",
6464
"multiaddr": "^7.2.1",
6565
"multistream-select": "^0.15.0",

src/connection-manager/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class ConnectionManager {
3737
this._libp2p = libp2p
3838
this._registrar = libp2p.registrar
3939
this._peerId = libp2p.peerInfo.id.toString()
40-
this._options = mergeOptions(defaultOptions, options)
40+
this._options = mergeOptions.call({ ignoreUndefined: true }, defaultOptions, options)
4141
assert(
4242
this._options.maxConnections > this._options.minConnections,
4343
'Connection Manager maxConnections must be greater than minConnections'

0 commit comments

Comments
 (0)