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

Fixes: #9548
This commit is contained in:
Jorropo 2023-01-17 19:18:39 +01:00 committed by Marcin Rataj
parent 1fa3a789d4
commit 73ebad1892
2 changed files with 70 additions and 0 deletions

View File

@ -67,6 +67,10 @@ func ResourceManager(cfg config.SwarmConfig) interface{} {
limitConfig = l
}
if err := ensureConnMgrMakeSenseVsRessourcesMgr(limitConfig, cfg.ConnMgr); err != nil {
return nil, opts, err
}
limiter := rcmgr.NewFixedLimiter(limitConfig)
str, err := rcmgrObs.NewStatsTraceReporter()
@ -598,3 +602,41 @@ func NetResetLimit(mgr network.ResourceManager, repo repo.Repo, scope string) (r
return result, nil
}
func ensureConnMgrMakeSenseVsRessourcesMgr(rcm rcmgr.LimitConfig, cmgr config.ConnMgr) error {
if cmgr.Type.WithDefault(config.DefaultConnMgrType) == "none" {
return nil // none connmgr, no checks to do
}
highWater := cmgr.HighWater.WithDefault(config.DefaultConnMgrHighWater)
if rcm.System.ConnsInbound <= rcm.System.Conns {
if int64(rcm.System.ConnsInbound) <= highWater {
// nolint
return fmt.Errorf(`
Unable to initialize libp2p due to conflicting limit configuration:
ResourceMgr.Limits.System.ConnsInbound (%d) must be bigger than ConnMgr.HighWater (%d)
`, rcm.System.ConnsInbound, highWater)
}
} else if int64(rcm.System.Conns) <= highWater {
// nolint
return fmt.Errorf(`
Unable to initialize libp2p due to conflicting limit configuration:
ResourceMgr.Limits.System.Conns (%d) must be bigger than ConnMgr.HighWater (%d)
`, rcm.System.Conns, highWater)
}
if rcm.System.StreamsInbound <= rcm.System.Streams {
if int64(rcm.System.StreamsInbound) <= highWater {
// nolint
return fmt.Errorf(`
Unable to initialize libp2p due to conflicting limit configuration:
ResourceMgr.Limits.System.StreamsInbound (%d) must be bigger than ConnMgr.HighWater (%d)
`, rcm.System.StreamsInbound, highWater)
}
} else if int64(rcm.System.Streams) <= highWater {
// nolint
return fmt.Errorf(`
Unable to initialize libp2p due to conflicting limit configuration:
ResourceMgr.Limits.System.Streams (%d) must be bigger than ConnMgr.HighWater (%d)
`, rcm.System.Streams, highWater)
}
return nil
}

View File

@ -227,4 +227,32 @@ test_expect_success 'stop iptb' '
iptb stop 2
'
## Test daemon refuse to start if connmgr.highwater < ressources inbound
test_expect_success "node refuse to start if Swarm.ResourceMgr.Limits.System.Conns <= Swarm.ConnMgr.HighWater" '
ipfs config --json Swarm.ResourceMgr.Limits.System.Conns 128 &&
ipfs config --json Swarm.ConnMgr.HighWater 128 &&
ipfs config --json Swarm.ConnMgr.LowWater 64 &&
test_expect_code 1 ipfs daemon &&
ipfs config --json Swarm.ResourceMgr.Limits.System.Conns 256
'
test_expect_success "node refuse to start if Swarm.ResourceMgr.Limits.System.ConnsInbound <= Swarm.ConnMgr.HighWater" '
ipfs config --json Swarm.ResourceMgr.Limits.System.ConnsInbound 128 &&
test_expect_code 1 ipfs daemon &&
ipfs config --json Swarm.ResourceMgr.Limits.System.ConnsInbound 256
'
test_expect_success "node refuse to start if Swarm.ResourceMgr.Limits.System.Streams <= Swarm.ConnMgr.HighWater" '
ipfs config --json Swarm.ResourceMgr.Limits.System.Streams 128 &&
test_expect_code 1 ipfs daemon &&
ipfs config --json Swarm.ResourceMgr.Limits.System.Streams 256
'
test_expect_success "node refuse to start if Swarm.ResourceMgr.Limits.System.StreamsInbound <= Swarm.ConnMgr.HighWater" '
ipfs config --json Swarm.ResourceMgr.Limits.System.StreamsInbound 128 &&
test_expect_code 1 ipfs daemon &&
ipfs config --json Swarm.ResourceMgr.Limits.System.StreamsInbound 256
'
test_done