From 7aa59ed152417e0c7bf86af16e3f8bbd4ae96567 Mon Sep 17 00:00:00 2001 From: Jorropo Date: Mon, 16 Jan 2023 12:02:40 +0100 Subject: [PATCH] fix: ensure connmgr is smaller then autoscalled ressource limits Fixes #9545 --- core/node/libp2p/rcmgr_defaults.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/node/libp2p/rcmgr_defaults.go b/core/node/libp2p/rcmgr_defaults.go index d3c2942584c..d2a7586d7f4 100644 --- a/core/node/libp2p/rcmgr_defaults.go +++ b/core/node/libp2p/rcmgr_defaults.go @@ -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 }