Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Callbackflow close exception misbehavior with timeout #4071

Closed
dddj698 opened this issue Mar 18, 2024 · 1 comment · Fixed by #4072
Closed

Callbackflow close exception misbehavior with timeout #4071

dddj698 opened this issue Mar 18, 2024 · 1 comment · Fixed by #4072

Comments

@dddj698
Copy link

dddj698 commented Mar 18, 2024

Describe the bug

When callbackflow is chained with timeout directly, and closed with an exception, the exception won't be sent to downstream.

Coroutines version 1.8.0. Kotlin version 1.9.21.

Provide a Reproducer

val flow = callbackFlow<Int> {
    close(IllegalStateException("Test Exception"))
}.timeout(5.seconds)
try {
    flow.collect()
} catch (e: Exception) {
    println("exception got: $e")
}

I expect this to print:
exception got: java.lang.IllegalStateException: Test Exception

But no exception is caught.

However, if I add any operator between callbackflow and timeout, it works as expected,

val flow = callbackFlow<Int> {
    close(IllegalStateException("Test Exception"))
}.catch{throw it}.timeout(5.seconds)
try {
    flow.collect()
} catch (e: Exception) {
    println("exception got: $e")
}
@dkhalanskyjb
Copy link
Collaborator

Will be fixed in 1.8.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants