Skip to content

Commit 402e6b5

Browse files
committed
fix: ensure connmgr is smaller then autoscalled ressource limits
Fixes ipfs#9545
1 parent d90a9b5 commit 402e6b5

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

config/init.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,10 @@ const DefaultConnMgrGracePeriod = time.Second * 20
110110
// type.
111111
const DefaultConnMgrType = "basic"
112112

113+
// DefaultResourceMgrMinInboundConns is a MAGIC number that probably a good
114+
// enough number of inbound conns to be a good network citizen.
115+
const DefaultResourceMgrMinInboundConns = 800
116+
113117
func addressesConfig() Addresses {
114118
return Addresses{
115119
Swarm: []string{

core/node/libp2p/rcmgr_defaults.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,23 @@ Run 'ipfs swarm limit all' to see the resulting limits.
186186

187187
defaultLimitConfig := scalingLimitConfig.Scale(int64(maxMemory), int(numFD))
188188

189+
// Simple checks to overide autoscaling ensuring limits make sense versus the connmgr values.
190+
// There are ways to break this, but this should catch most problems already.
191+
// We might improve this in the future.
192+
// See: https://github.com/ipfs/kubo/issues/9545
193+
if cfg.ConnMgr.Type == nil || cfg.ConnMgr.Type.String() != "none" {
194+
maxInboundConns := int64(defaultLimitConfig.System.ConnsInbound)
195+
if connmgrHighWaterTimesTwo := cfg.ConnMgr.HighWater.WithDefault(config.DefaultConnMgrHighWater) * 2; maxInboundConns < connmgrHighWaterTimesTwo {
196+
maxInboundConns = connmgrHighWaterTimesTwo
197+
}
198+
199+
if maxInboundConns < config.DefaultResourceMgrMinInboundConns {
200+
maxInboundConns = config.DefaultResourceMgrMinInboundConns
201+
}
202+
203+
defaultLimitConfig.System.StreamsInbound = int(maxInboundConns * int64(defaultLimitConfig.System.StreamsInbound) / int64(defaultLimitConfig.System.ConnsInbound))
204+
defaultLimitConfig.System.ConnsInbound = int(maxInboundConns)
205+
}
206+
189207
return defaultLimitConfig, nil
190208
}

0 commit comments

Comments
 (0)