Skip to content

Commit

Permalink
Fix Flow.timeout swallowing the channel closure exception (#4072)
Browse files Browse the repository at this point in the history
Fixes #4071
  • Loading branch information
dkhalanskyjb committed Mar 25, 2024
1 parent 60d2fe8 commit 0ca7358
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions kotlinx-coroutines-core/common/src/flow/operators/Delay.kt
Expand Up @@ -394,6 +394,7 @@ private fun <T> Flow<T>.timeoutInternal(
value.onSuccess {
downStream.emit(it)
}.onClosed {
it?.let { throw it }
return@onReceiveCatching false
}
return@onReceiveCatching true
Expand Down
11 changes: 11 additions & 0 deletions kotlinx-coroutines-core/common/test/flow/operators/TimeoutTest.kt
Expand Up @@ -237,6 +237,17 @@ class TimeoutTest : TestBase() {
testImmediateTimeout(-1.seconds)
}

@Test
fun testClosing() = runTest {
assertFailsWith<TestException> {
channelFlow<Int> { close(TestException()) }
.timeout(Duration.INFINITE)
.collect {
expectUnreached()
}
}
}

private fun testImmediateTimeout(timeout: Duration) {
expect(1)
val flow = emptyFlow<Int>().timeout(timeout)
Expand Down

0 comments on commit 0ca7358

Please sign in to comment.