Skip to content

Commit f113c91

Browse files
committed
Fix bug #6022
Signed-off-by: Anton Litvinov <[email protected]>
1 parent ac0db4e commit f113c91

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

services/wireguard/endpoint/netstack-provider/shaper_service.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@
1818
package netstack_provider
1919

2020
import (
21+
"time"
22+
2123
"github.com/mysteriumnetwork/node/config"
2224
"github.com/mysteriumnetwork/node/eventbus"
2325
"github.com/rs/zerolog/log"
2426
"golang.org/x/time/rate"
2527
)
2628

27-
const AppTopicConfigShaper = "config:shaper"
29+
const (
30+
AppTopicConfigShaper = "config:shaper"
31+
BurstLimit = 1000 * 1000 * 1000
32+
)
2833

2934
var rateLimiter *rate.Limiter
3035

@@ -33,7 +38,7 @@ func getRateLimitter() *rate.Limiter {
3338
}
3439

3540
func InitUserspaceShaper(eventBus eventbus.EventBus) {
36-
applyLimits := func(e interface{}) {
41+
applyLimits := func(_ interface{}) {
3742
bandwidthBytes := config.GetUInt64(config.FlagShaperBandwidth) * 1024
3843
bandwidth := rate.Limit(bandwidthBytes)
3944
if !config.GetBool(config.FlagShaperEnabled) {
@@ -43,9 +48,14 @@ func InitUserspaceShaper(eventBus eventbus.EventBus) {
4348
rateLimiter.SetLimit(bandwidth)
4449
}
4550

46-
rateLimiter = rate.NewLimiter(rate.Inf, 0)
51+
rateLimiter = rate.NewLimiter(rate.Inf, BurstLimit)
52+
rateLimiter.AllowN(time.Now(), BurstLimit) // spend initial burst
53+
4754
applyLimits(nil)
4855

56+
if eventBus == nil {
57+
return
58+
}
4959
err := eventBus.SubscribeAsync(AppTopicConfigShaper, applyLimits)
5060
if err != nil {
5161
log.Error().Msgf("could not subscribe to topic: %v", err)

0 commit comments

Comments
 (0)