forked from rook/rook
assignMons schedules each mon in its own goroutine and shares a failedMonSchedule bool to record whether any of them failed. The resultLock mutex already guards the shared c.mapping.Schedule map write, but the three failedMonSchedule = true assignments were done without holding the lock. When two or more mons fail to schedule at the same time (for example when waitForMonitorScheduling errors, the node choice is nil, or getNodeInfoFromNode fails) their goroutines write the flag concurrently, which is a write-write data race. Guard the failedMonSchedule writes with the existing resultLock, the same lock the goroutines already use for the map update. The post-Wait read is left as is since the WaitGroup orders it after every write. Add a regression test that fails scheduling for multiple mons at once and confirms assignMons returns an error; run it with -race to catch the race. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>