Skip to content

Commit cfb2f90

Browse files
committed
Lock before checking to swap runners
1 parent f5a1f44 commit cfb2f90

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

internal/server/server.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,15 @@ func (h *Handler) Shutdown(w http.ResponseWriter, r *http.Request) {
131131
func (h *Handler) updateRunner(srcDir string) error {
132132
log := logger.Sugar()
133133

134+
// Lock before checking to avoid thrashing runner replacements
135+
h.mu.Lock()
136+
defer h.mu.Unlock()
137+
134138
// Reuse current runner, nothing to do
135139
if h.runner != nil && h.runner.SrcDir() == srcDir {
136140
return nil
137141
}
138142

139-
// Need to start a new runner, lock until done
140-
h.mu.Lock()
141-
defer h.mu.Unlock()
142-
143143
// Different source URL, stop current runner
144144
if h.runner != nil {
145145
log.Infow("stopping procedure runner", "src_dir", h.runner.SrcDir())

0 commit comments

Comments
 (0)