Skip to content

Commit 8009b36

Browse files
committed
Fix OOM in ChannelAtomicCancelStressTest for LinkedListChannel
Sender must be slowed down when it goes too fast
1 parent 9b6e311 commit 8009b36

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

kotlinx-coroutines-core/jvm/test/channels/ChannelAtomicCancelStressTest.kt

+6-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,12 @@ class ChannelAtomicCancelStressTest(private val kind: TestChannelKind) : TestBas
115115
else -> error("cannot happen")
116116
}
117117
lastSent = trySend // update on success
118-
if (counter++ % 1000 == 0) yield() // yield periodically to check cancellation on LinkedListChannel
118+
when {
119+
// must artificially slow down LINKED_LIST sender to avoid overwhelming receiver and going OOM
120+
kind == TestChannelKind.LINKED_LIST -> while (lastSent > lastReceived + 100) yield()
121+
// yield periodically to check cancellation on conflated channels
122+
kind.isConflated -> if (counter++ % 100 == 0) yield()
123+
}
119124
}
120125
}
121126
}

0 commit comments

Comments
 (0)