fix: future proof with > rcmgr.DefaultLimit for new enum rcmgr values
Jorropo committed
Mar 15, 2023 at 17:40 UTC
a3b417779ca59f6329ae0d713b901537033a0c0a
3 files changed
+8
-8
core/node/libp2p/rcmgr.go
+4
-4
@@ -454,7 +454,7 @@ func ensureConnMgrMakeSenseVsResourceMgr(concreteLimits rcmgr.ConcreteLimitConfi
454
rcm := concreteLimits.ToPartialLimitConfig()
455
456
highWater := cfg.ConnMgr.HighWater.WithDefault(config.DefaultConnMgrHighWater)
457
- if rcm.System.Conns != rcmgr.Unlimited && int64(rcm.System.Conns) <= highWater {
457
+ if (rcm.System.Conns > rcmgr.DefaultLimit || rcm.System.Conns == rcmgr.BlockAllLimit) && int64(rcm.System.Conns) <= highWater {
458
// nolint
459
return fmt.Errorf(`
460
Unable to initialize libp2p due to conflicting resource manager limit configuration.
@@ -462,7 +462,7 @@ resource manager System.Conns (%d) must be bigger than ConnMgr.HighWater (%d)
462
See: https://github.com/ipfs/kubo/blob/master/docs/libp2p-resource-management.md#how-does-the-resource-manager-resourcemgr-relate-to-the-connection-manager-connmgr
463
`, rcm.System.Conns, highWater)
464
}
465
- if rcm.System.ConnsInbound != rcmgr.Unlimited && int64(rcm.System.ConnsInbound) <= highWater {
465
+ if (rcm.System.ConnsInbound > rcmgr.DefaultLimit || rcm.System.ConnsInbound == rcmgr.BlockAllLimit) && int64(rcm.System.ConnsInbound) <= highWater {
466
// nolint
467
return fmt.Errorf(`
468
Unable to initialize libp2p due to conflicting resource manager limit configuration.
@@ -470,7 +470,7 @@ resource manager System.ConnsInbound (%d) must be bigger than ConnMgr.HighWater
470
See: https://github.com/ipfs/kubo/blob/master/docs/libp2p-resource-management.md#how-does-the-resource-manager-resourcemgr-relate-to-the-connection-manager-connmgr
471
`, rcm.System.ConnsInbound, highWater)
472
}
473
- if rcm.System.Streams != rcmgr.Unlimited && int64(rcm.System.Streams) <= highWater {
473
+ if rcm.System.Streams > rcmgr.DefaultLimit || rcm.System.Streams == rcmgr.BlockAllLimit && int64(rcm.System.Streams) <= highWater {
474
// nolint
475
return fmt.Errorf(`
476
Unable to initialize libp2p due to conflicting resource manager limit configuration.
@@ -478,7 +478,7 @@ resource manager System.Streams (%d) must be bigger than ConnMgr.HighWater (%d)
478
See: https://github.com/ipfs/kubo/blob/master/docs/libp2p-resource-management.md#how-does-the-resource-manager-resourcemgr-relate-to-the-connection-manager-connmgr
479
`, rcm.System.Streams, highWater)
480
}
481
- if rcm.System.StreamsInbound != rcmgr.Unlimited && int64(rcm.System.StreamsInbound) <= highWater {
481
+ if (rcm.System.StreamsInbound > rcmgr.DefaultLimit || rcm.System.StreamsInbound == rcmgr.BlockAllLimit) && int64(rcm.System.StreamsInbound) <= highWater {
482
// nolint
483
return fmt.Errorf(`
484
Unable to initialize libp2p due to conflicting resource manager limit configuration.
core/node/libp2p/rcmgr_defaults.go
+2
-2
@@ -118,7 +118,7 @@ func createDefaultLimitConfig(cfg config.SwarmConfig) (limitConfig rcmgr.Concret
118
// There are ways to break this, but this should catch most problems already.
119
// We might improve this in the future.
120
// See: https://github.com/ipfs/kubo/issues/9545
121
- if partialLimits.System.ConnsInbound != rcmgr.Unlimited && cfg.ConnMgr.Type.WithDefault(config.DefaultConnMgrType) != "none" {
121
+ if partialLimits.System.ConnsInbound > rcmgr.DefaultLimit && cfg.ConnMgr.Type.WithDefault(config.DefaultConnMgrType) != "none" {
122
maxInboundConns := int64(partialLimits.System.ConnsInbound)
123
if connmgrHighWaterTimesTwo := cfg.ConnMgr.HighWater.WithDefault(config.DefaultConnMgrHighWater) * 2; maxInboundConns < connmgrHighWaterTimesTwo {
124
maxInboundConns = connmgrHighWaterTimesTwo
@@ -129,7 +129,7 @@ func createDefaultLimitConfig(cfg config.SwarmConfig) (limitConfig rcmgr.Concret
129
}
130
131
// Scale System.StreamsInbound as well, but use the existing ratio of StreamsInbound to ConnsInbound
132
- if partialLimits.System.StreamsInbound != rcmgr.Unlimited {
132
+ if partialLimits.System.StreamsInbound > rcmgr.DefaultLimit {
133
partialLimits.System.StreamsInbound = rcmgr.LimitVal(maxInboundConns * int64(partialLimits.System.StreamsInbound) / int64(partialLimits.System.ConnsInbound))
134
}
135
partialLimits.System.ConnsInbound = rcmgr.LimitVal(maxInboundConns)
test/cli/rcmgr_test.go
+2
-2
@@ -81,10 +81,10 @@ func TestRcmgr(t *testing.T) {
81
require.Equal(t, 0, res.ExitCode())
82
limits := unmarshalLimits(t, res.Stdout.Bytes())
83
84
- if limits.System.ConnsInbound != rcmgr.Unlimited {
84
+ if limits.System.ConnsInbound > rcmgr.DefaultLimit {
85
assert.GreaterOrEqual(t, limits.System.ConnsInbound, 800)
86
}
87
- if limits.System.StreamsInbound != rcmgr.Unlimited {
87
+ if limits.System.StreamsInbound > rcmgr.DefaultLimit {
88
assert.GreaterOrEqual(t, limits.System.StreamsInbound, 800)
89
}
90
})