fix: Data race on failedPromises in DeterministicRunnerImpl#1060
fix: Data race on failedPromises in DeterministicRunnerImpl#1060hcantunc wants to merge 1 commit into
Conversation
failedPromises (HashSet) is written to via registerFailedPromise/forgetFailedPromise without holding the lock, while close() reads it under the lock on another thread. Concurrent HashMap.put and HashMap.size is a data race. Replace HashSet with ConcurrentHashMap.newKeySet() so add/remove/copy are safe without requiring callers to hold the lock. Signed-off-by: Hünkar Tunç <tunc+UBER@uber.com>
c31211c to
3d74eac
Compare
CI failed: A unit test failure in 'WorkflowTest.testChildWorkflowWithCronSchedule' indicates a regression, where a cron workflow executed four times instead of the expected two. This likely stems from the recent changes to 'DeterministicRunnerImpl' intended to fix a data race.OverviewOne unit test failure was identified in the FailuresWorkflowTest.testChildWorkflowWithCronSchedule Failure (confidence: medium)
Summary
Code Review ✅ ApprovedReplaces HashSet with ConcurrentHashMap.newKeySet() in DeterministicRunnerImpl to eliminate the data race between lockless writes and locked reads. No issues found. Tip Comment OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
|
Do we have a unit test to cover the Data race on failedPromises case? |
What changed?
Replace
HashSetwithConcurrentHashMap.newKeySet()forfailedPromisesinDeterministicRunnerImpl.Why?
failedPromisesis written to viaregisterFailedPromise/forgetFailedPromisewithout holding the lock, whileclose()reads it under the lock on another thread.How did you test it?
Existing unit tests.
Potential risks
Minimal.
ConcurrentHashMap.newKeySet()is a drop-in replacement forHashSetbut has slightly higher memory overhead and per-operation.Release notes
N/A
Documentation Changes
N/A