Run Blocking In Suspend
ID |
kotlin.run_blocking_in_suspend |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Kotlin |
Tags |
concurrency, reliability |
Rationale
suspend fun fetch() {
runBlocking { delay(100) } // FLAW
}
A suspend function is already running on a coroutine dispatcher. Calling
runBlocking from inside it blocks the underlying OS thread until the child
coroutine completes, starving the dispatcher’s thread pool. On small pools
(such as the default Android UI dispatcher) this can deadlock the entire
application.