From 562711e4175a940a053f40287ac6e35890c7ee6d Mon Sep 17 00:00:00 2001 From: dufrannea Date: Thu, 8 Mar 2018 19:50:15 +0100 Subject: [PATCH] Fixes race condition in waiting execution queue (#246) When several actions were queued concurrently in the same WaitingExecutionQueue, only the last one remained. --- .../com/criteo/cuttle/platforms/WaitingExecutionQueue.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/com/criteo/cuttle/platforms/WaitingExecutionQueue.scala b/core/src/main/scala/com/criteo/cuttle/platforms/WaitingExecutionQueue.scala index 522440b00..ce3f96514 100644 --- a/core/src/main/scala/com/criteo/cuttle/platforms/WaitingExecutionQueue.scala +++ b/core/src/main/scala/com/criteo/cuttle/platforms/WaitingExecutionQueue.scala @@ -37,7 +37,11 @@ trait WaitingExecutionQueue { } lazy val _running = Ref(Set.empty[(Execution[_], DelayedResult[_])]) - lazy val _waiting = Ref(SortedSet.empty[(Execution[_], DelayedResult[_])](Ordering.by(_._1))) + lazy val _waiting = Ref( + SortedSet.empty[(Execution[_ <: Scheduling], DelayedResult[_])]( + Ordering.by[(Execution[_ <: Scheduling], DelayedResult[_]), (Execution[_], Int)]({ + case (execution, delayedResult) => execution -> delayedResult.hashCode + }))) def waiting: Set[Execution[_]] = _waiting.single().map(_._1) def running: Set[Execution[_]] = _running.single().map(_._1)