Skip to content

Commit 0f8ab25

Browse files
committed
address race condition in initial tick
1 parent 591dd91 commit 0f8ab25

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

coderd/database/dbpurge/dbpurge.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, clk quartz.
3131
//nolint:gocritic // The system purges old db records without user input.
3232
ctx = dbauthz.AsSystemRestricted(ctx)
3333

34-
ticker := clk.NewTicker(time.Nanosecond)
34+
// Start the ticker with the initial delay.
35+
ticker := clk.NewTicker(delay)
3536
doTick := func(start time.Time) {
3637
defer ticker.Reset(delay)
3738
// Start a transaction to grab advisory lock, we don't want to run
@@ -74,6 +75,8 @@ func New(ctx context.Context, logger slog.Logger, db database.Store, clk quartz.
7475
go func() {
7576
defer close(closed)
7677
defer ticker.Stop()
78+
// Force an initial tick immediately.
79+
ticker.Reset(time.Nanosecond)
7780
for {
7881
select {
7982
case <-ctx.Done():

0 commit comments

Comments
 (0)