Skip to content

Commit aba30f6

Browse files
authored
dockercomposeservice: fix race conditions (#6718)
- one missing mutex lock - one flaky test Signed-off-by: Nick Santos <nicholas.j.santos@gmail.com>
1 parent 9cf7756 commit aba30f6

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

internal/controllers/core/dockercomposeservice/disable_watcher_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ Going to remove servantes_fortune_1
3737
f.clock.Advance(20 * disableDebounceDelay)
3838
f.startTime = f.clock.Now()
3939

40-
f.log.AssertEventuallyContains(t, "Stopping servantes", time.Second)
4140
expectedOutput := strings.Replace(f.dcClient.RmOutput, "Going to remove servantes_fortune_1\n", "", -1)
41+
// Wait for the last expected line to ensure all output has been written to the log.
42+
// filteredWriter writes each line individually, so checking for an early line
43+
// (e.g. "Stopping servantes") can race with later lines not yet being written.
44+
f.log.AssertEventuallyContains(t, "Removing servantes_fortune_1 ... done", time.Second)
4245
require.Equal(t, expectedOutput, f.log.String())
4346
}
4447

internal/controllers/core/dockercomposeservice/reconciler.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,10 +443,12 @@ func (r *Reconciler) forceApplyHelper(
443443
// Update the status on the apiserver if necessary.
444444
func (r *Reconciler) maybeUpdateStatus(ctx context.Context, nn types.NamespacedName, obj *v1alpha1.DockerComposeService) error {
445445
newStatus := v1alpha1.DockerComposeServiceStatus{}
446+
r.mu.Lock()
446447
existing, ok := r.results[nn]
447448
if ok {
448449
newStatus = existing.Status
449450
}
451+
r.mu.Unlock()
450452

451453
if apicmp.DeepEqual(obj.Status, newStatus) {
452454
return nil

0 commit comments

Comments
 (0)