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

coroutines-reactor: subscriberContext not available in suspended functions #1212

Closed
FrontierPsychiatrist opened this issue May 21, 2019 · 2 comments
Labels

Comments

@FrontierPsychiatrist
Copy link

FrontierPsychiatrist commented May 21, 2019

When using the mono coroutine and awaitSingle for the subscriber context in the suspended function it seems the subscriber context is not "propagated".

This example prints Context0{} when Context1{foo=bar} is expected.

Using reactor 3.3.0.M1, kotlin-coroutines 1.2.1

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.reactive.awaitSingle
import kotlinx.coroutines.reactor.mono
import reactor.core.publisher.Mono
import reactor.util.context.Context

suspend fun test() {
    val ctx = Mono.subscriberContext().awaitSingle()
    println(ctx)
}

fun main() {
    CoroutineScope(Dispatchers.Unconfined).mono {
        test()
    }.subscriberContext(Context.of("foo", "bar"))
            .block()
}

I tried to understand the code to see where this is coming from but sadly couldn't understand it. The sink in Mono.defer has the subscriber context correctly available, this I saw while debugging.

@qwwdfsad
Copy link
Contributor

qwwdfsad commented May 21, 2019

This is the expected behaviour (for now).
You have two independent monos: one created with CoroutineScope(Dispatchers.Unconfined).mono and another one created and immediately subscribed with Mono.subscriberContext().awaitSingle(). They have nothing in common and thus one context is not propagated to another one.

There may be changed in #284 though

@FrontierPsychiatrist
Copy link
Author

Ok, that makes sense. Thanks for the information, I'll follow that ticket then!

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

2 participants