Skip to content

Commit 40e0a38

Browse files
dkhalanskyjbknisht
authored andcommitted
Fix Flow.timeout swallowing the channel closure exception (Kotlin#4072)
Fixes Kotlin#4071
1 parent 969f852 commit 40e0a38

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

kotlinx-coroutines-core/common/src/flow/operators/Delay.kt

+1
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ private fun <T> Flow<T>.timeoutInternal(
394394
value.onSuccess {
395395
downStream.emit(it)
396396
}.onClosed {
397+
it?.let { throw it }
397398
return@onReceiveCatching false
398399
}
399400
return@onReceiveCatching true

kotlinx-coroutines-core/common/test/flow/operators/TimeoutTest.kt

+11
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,17 @@ class TimeoutTest : TestBase() {
237237
testImmediateTimeout(-1.seconds)
238238
}
239239

240+
@Test
241+
fun testClosing() = runTest {
242+
assertFailsWith<TestException> {
243+
channelFlow<Int> { close(TestException()) }
244+
.timeout(Duration.INFINITE)
245+
.collect {
246+
expectUnreached()
247+
}
248+
}
249+
}
250+
240251
private fun testImmediateTimeout(timeout: Duration) {
241252
expect(1)
242253
val flow = emptyFlow<Int>().timeout(timeout)

0 commit comments

Comments
 (0)