Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limitedParallelism does not propagate the full CoroutineContext to the underlying dispatcher #4305

Open
dkhalanskyjb opened this issue Dec 19, 2024 · 0 comments
Labels

Comments

@dkhalanskyjb
Copy link
Collaborator

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

override fun dispatch(context: CoroutineContext, block: Runnable) {
dispatchInternal(block) { worker ->
dispatcher.dispatch(this, worker)
}
}
@InternalCoroutinesApi
override fun dispatchYield(context: CoroutineContext, block: Runnable) {
dispatchInternal(block) { worker ->
dispatcher.dispatchYield(this, worker)
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant