mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
fix: concurrent writes to executor stats (#7731)
Signed-off-by: Spike Curtis <spike@coder.com>
This commit is contained in:
@ -3,6 +3,7 @@ package executor
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -89,6 +90,8 @@ func (e *Executor) runOnce(t time.Time) Stats {
|
|||||||
stats := Stats{
|
stats := Stats{
|
||||||
Transitions: make(map[uuid.UUID]database.WorkspaceTransition),
|
Transitions: make(map[uuid.UUID]database.WorkspaceTransition),
|
||||||
}
|
}
|
||||||
|
// we build the map of transitions concurrently, so need a mutex to serialize writes to the map
|
||||||
|
statsMu := sync.Mutex{}
|
||||||
defer func() {
|
defer func() {
|
||||||
stats.Elapsed = time.Since(t)
|
stats.Elapsed = time.Since(t)
|
||||||
stats.Error = err
|
stats.Error = err
|
||||||
@ -188,7 +191,9 @@ func (e *Executor) runOnce(t time.Time) Stats {
|
|||||||
)
|
)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
statsMu.Lock()
|
||||||
stats.Transitions[ws.ID] = validTransition
|
stats.Transitions[ws.ID] = validTransition
|
||||||
|
statsMu.Unlock()
|
||||||
|
|
||||||
log.Info(e.ctx, "scheduling workspace transition", slog.F("transition", validTransition))
|
log.Info(e.ctx, "scheduling workspace transition", slog.F("transition", validTransition))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user