A coroutine is started in GlobalScope, which no caller can cancel or wait for
What it finds
GlobalScope.launch { ... }: a coroutine in GlobalScope belongs to no parent, so it is neither cancelled with the code that started it nor waited for, and its failures reach no caller. The coroutines guide calls the scope delicate for this reason and recommends a scope tied to the lifetime of the work.
Reported for a call on GlobalScope when the file can see kotlinx.coroutines.GlobalScope and declares no GlobalScope of its own. A call under @OptIn(DelicateCoroutinesApi::class), the opt-in the library asks for, is left alone.
From the rule's source, global_scope_coroutine.rs.
import kotlinx.coroutines.* class Uploader(private val scope: CoroutineScope) { fun upload(file: String) { GlobalScope.launch { send(file) }tx0 reports: GlobalScope.launch starts a coroutine val result = GlobalScope.async { size(file) }tx0 reports: GlobalScope.async starts scope.launch { send(file) } println(GlobalScope.coroutineContext) }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:global-scope-coroutine" = "warning"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:global-scope-coroutine] reason="..."tx0 explain tx0/kotlin:global-scope-coroutine shows the same in the terminal. Found a false positive? Report it.