Skip to content

Commit

Permalink
fix: refuse to start if connmgr is smaller than ressource limits and …
Browse files Browse the repository at this point in the history
…not using none connmgr

Fixes: #9548
  • Loading branch information
Jorropo committed Jan 18, 2023
1 parent d90a9b5 commit 59b5ca0
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
42 changes: 42 additions & 0 deletions core/node/libp2p/rcmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
28 changes: 28 additions & 0 deletions test/sharness/t0139-swarm-rcmgr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 59b5ca0

Please sign in to comment.