Skip to content

Coroutines guide should warn about cancellation exceptions when transferring resources across suspension points #4413

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

Open
dkhalanskyjb opened this issue Apr 15, 2025 · 0 comments
Labels
guide Issues with the coroutines guide on the website

Comments

@dkhalanskyjb
Copy link
Collaborator

Originally reported by Uli Luckas in the Kotlinlang Slack: https://kotlinlang.slack.com/archives/C1CFAFJSK/p1742815571506039?thread_ts=1742814326.569149&cid=C1CFAFJSK

The caveat with how withContext may drop closeable resources (#3504) should be highlighted in the guide:

val socket = withContext(Dispatchers.IO) {
  Socket("localhost", 8080)
} // CancellationException can be thrown here, after the resource gets created
socket.use {
  // ...
}

The same goes for prompt cancellation guarantees in the other APIs.

@dkhalanskyjb dkhalanskyjb added the guide Issues with the coroutines guide on the website label Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
guide Issues with the coroutines guide on the website
Projects
None yet
Development

No branches or pull requests

1 participant