Skip to content

Commit abab11c

Browse files
committed
better fix
1 parent ed069e8 commit abab11c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

coderd/batchstats/batcher.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ func (b *Batcher) Add(
175175
// Run runs the batcher.
176176
func (b *Batcher) run(ctx context.Context) {
177177
// nolint:gocritic // This is only ever used for one thing - inserting agent stats.
178-
authCtx := dbauthz.AsSystemRestricted(context.Background())
178+
authCtx := dbauthz.AsSystemRestricted(ctx)
179179
for {
180180
select {
181181
case <-b.tickCh:
@@ -185,7 +185,13 @@ func (b *Batcher) run(ctx context.Context) {
185185
b.flush(authCtx, true, "reaching capacity")
186186
case <-ctx.Done():
187187
b.log.Debug(ctx, "context done, flushing before exit")
188-
b.flush(authCtx, true, "exit")
188+
189+
// We must create a new context here as the parent context is done.
190+
ctxTimeout, cancel := context.WithTimeout(context.Background(), 15*time.Second)
191+
defer cancel() //nolint:revive // We're returning, defer is fine.
192+
193+
// nolint:gocritic // This is only ever used for one thing - inserting agent stats.
194+
b.flush(dbauthz.AsSystemRestricted(ctxTimeout), true, "exit")
189195
return
190196
}
191197
}

0 commit comments

Comments
 (0)