kotlinx.coroutines icon indicating copy to clipboard operation
kotlinx.coroutines copied to clipboard

`limitedParallelism` does not propagate the full `CoroutineContext` to the underlying dispatcher

Open dkhalanskyjb opened this issue 11 months ago • 0 comments
trafficstars

import kotlinx.coroutines.*
import kotlin.coroutines.*

object MyDispatcher: CoroutineDispatcher() {    
    override fun dispatch(context: CoroutineContext, block: Runnable) {
        println(context)
        block.run()
    }
}

fun main() {
    val newDispatcher = MyDispatcher.limitedParallelism(2)
    newDispatcher.dispatch(CoroutineName("Hi!"), Runnable { })
}

prints

LimitedDispatcher@4459eb14

No CoroutineName in sight.

https://pl.kotl.in/86W-MnSGn

This bug was not reported to us as any production issue, but was found accidentally by reading https://github.com/Kotlin/kotlinx.coroutines/blob/6c6df2b850382887462eeaf51f21f58bd982491d/kotlinx-coroutines-core/common/src/internal/LimitedDispatcher.kt#L43-L54

dkhalanskyjb avatar Dec 19 '24 13:12 dkhalanskyjb