Skip to content
This repository was archived by the owner on Mar 24, 2023. It is now read-only.

Commit 45c9b00

Browse files
authored
Merge pull request #937 from laverya/state-completion-race-condition
finish writing to stepsCompleted before allowing next step to read it
2 parents fe248e2 + 40be8a7 commit 45c9b00

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pkg/lifecycle/daemon/routes_navcycle.go

+9
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ type NavcycleRoutes struct {
5858

5959
// Prevent data races when registering preexecute functions
6060
mut sync.Mutex
61+
62+
// Prevent a race when registering completed steps and starting the next step
63+
completeMut sync.Mutex
6164
}
6265

6366
// Register registers routes
@@ -141,6 +144,12 @@ func (d *NavcycleRoutes) maybeAbortDueToMissingRequirement(requires []string, c
141144
// although from a UI perspective the order is probably not strictly defined
142145
func (d *NavcycleRoutes) getRequiredButIncompleteStepFor(requires []string) (string, error) {
143146
debug := level.Debug(log.With(d.Logger, "method", "getRequiredButIncompleteStepFor"))
147+
if len(requires) == 0 {
148+
return "", nil
149+
}
150+
151+
d.completeMut.Lock()
152+
defer d.completeMut.Unlock()
144153

145154
stepsCompleted := map[string]interface{}{}
146155
currentState, err := d.StateManager.TryLoad()

pkg/lifecycle/daemon/routes_navcycle_completestep.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ func (d *NavcycleRoutes) completeStep(c *gin.Context) {
4848
// hack, give it 10 ms in case its an instant step. Hydrate and send will read progress from the syncMap
4949
time.Sleep(10 * time.Millisecond)
5050

51+
d.completeMut.Lock()
5152
d.hydrateAndSend(step, c)
52-
go d.handleAsync(errChan, debug, step, stepID)
53+
go func() {
54+
defer d.completeMut.Unlock()
55+
d.handleAsync(errChan, debug, step, stepID)
56+
}()
5357
return
5458
}
5559
d.errNotFound(c)

0 commit comments

Comments
 (0)