Skip to content

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

Open
@dkhalanskyjb

Description

@dkhalanskyjb

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    guideIssues with the coroutines guide on the website

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions