Skip to content

Commit a46e8f2

Browse files
authored
fix: concurrent writes to executor stats (#7731)
Signed-off-by: Spike Curtis <spike@coder.com>
1 parent 9810339 commit a46e8f2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

coderd/autobuild/executor/lifecycle_executor.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package executor
33
import (
44
"context"
55
"database/sql"
6+
"sync"
67
"sync/atomic"
78
"time"
89

@@ -89,6 +90,8 @@ func (e *Executor) runOnce(t time.Time) Stats {
8990
stats := Stats{
9091
Transitions: make(map[uuid.UUID]database.WorkspaceTransition),
9192
}
93+
// we build the map of transitions concurrently, so need a mutex to serialize writes to the map
94+
statsMu := sync.Mutex{}
9295
defer func() {
9396
stats.Elapsed = time.Since(t)
9497
stats.Error = err
@@ -188,7 +191,9 @@ func (e *Executor) runOnce(t time.Time) Stats {
188191
)
189192
return nil
190193
}
194+
statsMu.Lock()
191195
stats.Transitions[ws.ID] = validTransition
196+
statsMu.Unlock()
192197

193198
log.Info(e.ctx, "scheduling workspace transition", slog.F("transition", validTransition))
194199

0 commit comments

Comments
 (0)