Skip to content

Commit 218fe4a

Browse files
authored
pkg/settings/limits: fix double close (#1812)
1 parent ee6c9d2 commit 218fe4a

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

pkg/settings/limits/gate.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,7 @@ func (g *gateLimiter) get(ctx context.Context) (tenant string, open bool, err er
192192
actual, loaded := g.updaters.LoadOrStore(tenant, u)
193193
creCtx := contexts.WithCRE(ctx, g.scope.RoundCRE(contexts.CREValue(ctx)))
194194
if !loaded {
195-
// OPT: restore with support for SettingMap
196-
//u.cre.Store(cre)
197-
//go u.updateLoop(cre)
198-
close(u.done)
195+
go u.updateLoop(creCtx)
199196
} else {
200197
u = actual.(*updater[bool])
201198
u.updateCtx(creCtx)

pkg/settings/limits/resource.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ type waiter[N Number] struct {
152152
}
153153

154154
type resourcePoolUsage[N Number] struct {
155-
*resourcePoolLimiter[N]
155+
resourcePoolLimiter[N]
156156
scope settings.Scope // optional
157157
tenant string // optional
158158
mu sync.Mutex
@@ -185,10 +185,9 @@ func (u *resourcePoolUsage[N]) onLimitUpdate() {
185185

186186
func (l *resourcePoolLimiter[N]) newLimitUsage(opts ...metric.RecordOption) *resourcePoolUsage[N] {
187187
u := resourcePoolUsage[N]{
188-
resourcePoolLimiter: l,
189-
queue: make([]*waiter[N], 0),
190-
stopCh: make(services.StopChan),
191-
done: make(chan struct{}),
188+
queue: make([]*waiter[N], 0),
189+
stopCh: make(services.StopChan),
190+
done: make(chan struct{}),
192191
recordUsage: func(ctx context.Context, n N) {
193192
if l.recordUsage != nil {
194193
l.recordUsage(ctx, n, opts...)
@@ -215,6 +214,9 @@ func (l *resourcePoolLimiter[N]) newLimitUsage(opts ...metric.RecordOption) *res
215214
}
216215
},
217216
}
217+
// copy but replace updater
218+
u.resourcePoolLimiter = *l
219+
u.resourcePoolLimiter.updater = newUpdater(l.lggr, l.getLimitFn, l.subFn)
218220
return &u
219221
}
220222

@@ -384,8 +386,6 @@ func newUnscopedResourcePoolLimiter[N Number](defaultLimit N) *unscopedResourceP
384386
return l
385387
}
386388

387-
func recordNoop[T any](ctx context.Context, value T) {}
388-
389389
func (u *unscopedResourcePoolLimiter[N]) Limit(ctx context.Context) (N, error) {
390390
return u.get(ctx)
391391
}

0 commit comments

Comments
 (0)