Skip to content

Commit 457bb11

Browse files
hcantuncHünkar Tunç
andauthored
fix: Data race on failedPromises in DeterministicRunnerImpl (#1060)
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> Co-authored-by: Hünkar Tunç <tunc+UBER@uber.com>
1 parent 806febb commit 457bb11

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/main/java/com/uber/cadence/internal/sync/DeterministicRunnerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.util.Random;
5454
import java.util.Set;
5555
import java.util.UUID;
56+
import java.util.concurrent.ConcurrentHashMap;
5657
import java.util.concurrent.ExecutionException;
5758
import java.util.concurrent.ExecutorService;
5859
import java.util.concurrent.Future;
@@ -121,7 +122,7 @@ static void setCurrentThreadInternal(WorkflowThread coroutine) {
121122
* Used to check for failedPromises that contain an error, but never where accessed. It is to
122123
* avoid failure swallowing by failedPromises which is very hard to troubleshoot.
123124
*/
124-
private Set<Promise> failedPromises = new HashSet<>();
125+
private Set<Promise> failedPromises = ConcurrentHashMap.newKeySet();
125126

126127
private boolean exitRequested;
127128
private Object exitValue;

0 commit comments

Comments
 (0)