Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refuse to start if soft ConnMgr limits are bigger than hard ResourceMgr limits #9560

Merged
merged 1 commit into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ensureConnMgrMakeSenseVsRessourcesMgr → ensureConnMgrMakeSenseVsResourceMgr
(extra s' in Ressources)

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
lidel marked this conversation as resolved.
Show resolved Hide resolved
'

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