Skip to content

Commit 6ff59ca

Browse files
author
Roman Janusz
committed
fixing race condition in ObservableBlockingIterator
1 parent d63baef commit 6ff59ca

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

commons-core/jvm/src/main/scala/com/avsystem/commons/concurrent/ObservableBlockingIterator.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@ class ObservableBlockingIterator[T](
6767
// after the queue got full, wait until at least half of its capacity is free before letting
6868
// the Observable produce more elements
6969
if (promise != null && queue.remainingCapacity >= bufferSize / 2) {
70-
promise.success(Ack.Continue)
70+
// unsetting promise must happen before completing the promise or otherwise we risk throwing away
71+
// some other promise set by `onNext` before it could be completed
7172
ackPromise = null
73+
promise.success(Ack.Continue)
7274
}
7375
last
7476
case nonEmpty =>

0 commit comments

Comments
 (0)