Skip to content

Commit

Permalink
fix: ensure connmgr is smaller then autoscalled ressource limits
Browse files Browse the repository at this point in the history
Fixes #9545
  • Loading branch information
Jorropo committed Jan 16, 2023
1 parent d90a9b5 commit 7aa59ed
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions core/node/libp2p/rcmgr_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,5 +186,23 @@ Run 'ipfs swarm limit all' to see the resulting limits.

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

// Simple checks to overide autoscaling ensuring limits make sense versus the connmgr values.
// There are ways to break this, but this should catch most problems already.
// We might improve this in the future.
// See: https://github.com/ipfs/kubo/issues/9545
if cfg.ConnMgr.Type == nil || cfg.ConnMgr.Type.String() != "none" {
maxInboundConns := int64(defaultLimitConfig.System.ConnsInbound)
if connmgrHighWaterTimesTwo := cfg.ConnMgr.HighWater.WithDefault(config.DefaultConnMgrHighWater) * 2; maxInboundConns < connmgrHighWaterTimesTwo {
maxInboundConns = connmgrHighWaterTimesTwo
}
// MAGIC: 800 is probably a good enough number to be a good network citizen.
if maxInboundConns < 800 {
maxInboundConns = 800
}

defaultLimitConfig.System.StreamsInbound = int(maxInboundConns * int64(defaultLimitConfig.System.StreamsInbound) / int64(defaultLimitConfig.System.ConnsInbound))
defaultLimitConfig.System.ConnsInbound = int(maxInboundConns)
}

return defaultLimitConfig, nil
}

0 comments on commit 7aa59ed

Please sign in to comment.