@cryptotaxi247 / kubo / commits / c4cc21dcc

fix: refuse to start if connmgr is smaller than ressource limits and not using none connmgr

Fixes: #9548

Jorropo committed Jan 17, 2023 at 19:18 UTC c4cc21dcca8747f2cbd61280a76714136381852c
2 files changed +70
core/node/libp2p/rcmgr.go
+42
@@ -67,6 +67,10 @@ func ResourceManager(cfg config.SwarmConfig) interface{} {
67 limitConfig = l
68 }
69
70 + if err := ensureConnMgrMakeSenseVsRessourcesMgr(limitConfig, cfg.ConnMgr); err != nil {
71 + return nil, opts, err
72 + }
73 +
74 limiter := rcmgr.NewFixedLimiter(limitConfig)
75
76 str, err := rcmgrObs.NewStatsTraceReporter()
@@ -598,3 +602,41 @@ func NetResetLimit(mgr network.ResourceManager, repo repo.Repo, scope string) (r
602
603 return result, nil
604 }
605 +
606 +func ensureConnMgrMakeSenseVsRessourcesMgr(rcm rcmgr.LimitConfig, cmgr config.ConnMgr) error {
607 + if cmgr.Type.WithDefault(config.DefaultConnMgrType) == "none" {
608 + return nil // none connmgr, no checks to do
609 + }
610 + highWater := cmgr.HighWater.WithDefault(config.DefaultConnMgrHighWater)
611 + if rcm.System.ConnsInbound <= rcm.System.Conns {
612 + if int64(rcm.System.ConnsInbound) <= highWater {
613 + // nolint
614 + return fmt.Errorf(`
615 +Unable to initialize libp2p due to conflicting limit configuration:
616 +ResourceMgr.Limits.System.ConnsInbound (%d) must be bigger than ConnMgr.HighWater (%d)
617 +`, rcm.System.ConnsInbound, highWater)
618 + }
619 + } else if int64(rcm.System.Conns) <= highWater {
620 + // nolint
621 + return fmt.Errorf(`
622 +Unable to initialize libp2p due to conflicting limit configuration:
623 +ResourceMgr.Limits.System.Conns (%d) must be bigger than ConnMgr.HighWater (%d)
624 +`, rcm.System.Conns, highWater)
625 + }
626 + if rcm.System.StreamsInbound <= rcm.System.Streams {
627 + if int64(rcm.System.StreamsInbound) <= highWater {
628 + // nolint
629 + return fmt.Errorf(`
630 +Unable to initialize libp2p due to conflicting limit configuration:
631 +ResourceMgr.Limits.System.StreamsInbound (%d) must be bigger than ConnMgr.HighWater (%d)
632 +`, rcm.System.StreamsInbound, highWater)
633 + }
634 + } else if int64(rcm.System.Streams) <= highWater {
635 + // nolint
636 + return fmt.Errorf(`
637 +Unable to initialize libp2p due to conflicting limit configuration:
638 +ResourceMgr.Limits.System.Streams (%d) must be bigger than ConnMgr.HighWater (%d)
639 +`, rcm.System.Streams, highWater)
640 + }
641 + return nil
642 +}
test/sharness/t0139-swarm-rcmgr.sh
+28
@@ -227,4 +227,32 @@ test_expect_success 'stop iptb' '
227 iptb stop 2
228 '
229
230 +## Test daemon refuse to start if connmgr.highwater < ressources inbound
231 +
232 +test_expect_success "node refuse to start if Swarm.ResourceMgr.Limits.System.Conns <= Swarm.ConnMgr.HighWater" '
233 + ipfs config --json Swarm.ResourceMgr.Limits.System.Conns 128 &&
234 + ipfs config --json Swarm.ConnMgr.HighWater 128 &&
235 + ipfs config --json Swarm.ConnMgr.LowWater 64 &&
236 + test_expect_code 1 ipfs daemon &&
237 + ipfs config --json Swarm.ResourceMgr.Limits.System.Conns 256
238 +'
239 +
240 +test_expect_success "node refuse to start if Swarm.ResourceMgr.Limits.System.ConnsInbound <= Swarm.ConnMgr.HighWater" '
241 + ipfs config --json Swarm.ResourceMgr.Limits.System.ConnsInbound 128 &&
242 + test_expect_code 1 ipfs daemon &&
243 + ipfs config --json Swarm.ResourceMgr.Limits.System.ConnsInbound 256
244 +'
245 +
246 +test_expect_success "node refuse to start if Swarm.ResourceMgr.Limits.System.Streams <= Swarm.ConnMgr.HighWater" '
247 + ipfs config --json Swarm.ResourceMgr.Limits.System.Streams 128 &&
248 + test_expect_code 1 ipfs daemon &&
249 + ipfs config --json Swarm.ResourceMgr.Limits.System.Streams 256
250 +'
251 +
252 +test_expect_success "node refuse to start if Swarm.ResourceMgr.Limits.System.StreamsInbound <= Swarm.ConnMgr.HighWater" '
253 + ipfs config --json Swarm.ResourceMgr.Limits.System.StreamsInbound 128 &&
254 + test_expect_code 1 ipfs daemon &&
255 + ipfs config --json Swarm.ResourceMgr.Limits.System.StreamsInbound 256
256 +'
257 +
258 test_done