A coroutine dispatcher with threads of its own is created, which has to be closed
What it finds
newSingleThreadContext and newFixedThreadPoolContext create threads that live until the dispatcher is closed. The coroutines library marks them as delicate: a dispatcher that is created repeatedly or never closed leaks threads. Dispatchers.Default or Dispatchers.IO.limitedParallelism(n) share threads instead.
From the rule's source, dedicated_thread_context.rs.
val worker = newSingleThreadContext("worker")tx0 reports: newSingleThreadContext creates threadsval pool = newFixedThreadPoolContext(4, "pool")tx0 reports: newFixedThreadPoolContext creates threadsval shared = Dispatchers.IO.limitedParallelism(4) Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/kotlin:dedicated-thread-context" = "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:dedicated-thread-context] reason="..."tx0 explain tx0/kotlin:dedicated-thread-context shows the same in the terminal. Found a false positive? Report it.