A suspend function is marked @Synchronized, whose lock is released at every suspension

tx0/kotlin:synchronized-suspend-functiondefaultwarningreliability/concurrencydepth fastbug, concurrency

What it finds

@Synchronized takes the object's monitor while the function body runs on a thread. A suspend function gives up its thread at each suspension point, and the code after it may run on another thread, so the monitor no longer guards the function as a whole. The coroutines guide uses Mutex.withLock for mutual exclusion in suspending code.

From the rule's source, synchronized_suspend.rs.

Example from the rule's tests
class Store {    @Synchronized    suspend fun save() {tx0 reports: @Synchronized does not hold its lock across the suspensions        delay(10)    }     @Synchronized    fun load() {}     suspend fun clear() {}}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:synchronized-suspend-function" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/kotlin:synchronized-suspend-function] reason="..."

tx0 explain tx0/kotlin:synchronized-suspend-function shows the same in the terminal. Found a false positive? Report it.