Hei. I am seeing few issues with `evalOn`, and `co...
# arrow
s
Hei. I am seeing few issues with
evalOn
, and
coroutineContexts
. Made 2 test files to show what is happening and what I expect. https://github.com/satyamagarwal/arrow-issues/tree/master/src/test/kotlin/com/arrow/issues Can any one help me please ? feel free to take a pull and test it out.
r
Hi Satyam, Do you get the same behavior if insted of the KotlinX runners you use the Arrow Fx Coroutines ones https://github.com/arrow-kt/arrow-fx/blob/master/arrow-fx-coroutines/src/main/kotlin/arrow/fx/coroutines/Enviroment.kt#L39 ?
s
@raulraja Replaced this line https://github.com/satyamagarwal/arrow-issues/blob/master/src/test/kotlin/com/arrow/issues/CoroutinesTest.kt#L27 with
Environment(MDCContext()).unsafeRunSync {
Same result.
Copy code
in test, key: myValue
I am in main
in runBlocking, key: myValue
I am in parTupledN, ForkJoinPool-1-worker-3
in parTupledN block, key: null
I am in parTupledN, ForkJoinPool-1-worker-5
in parTupledN block, key: null
I am in ForkJoinPool-1-worker-3
in either block, key: null
I am in ForkJoinPool-1-worker-5
in evalOn block, key: null
Evaluated thread result : ForkJoinPool-1-worker-5 in ForkJoinPool-1-worker-5
in either block after evalOn, key: null
I am in ForkJoinPool-1-worker-5
in parTupledN block after evalOn, key: null
I am in ForkJoinPool-1-worker-3
in parTupledN block after evalOn, key: null
Evaluated either block result : ForkJoinPool-1-worker-5 in ForkJoinPool-1-worker-3
in mdcContext after either block, key: null
in test, key: myValue
with original program :
Copy code
in test, key: myValue
I am in main @coroutine#3
in runBlocking, key: myValue
I am in parTupledN, ForkJoinPool-1-worker-3
in parTupledN block, key: null
I am in parTupledN, ForkJoinPool-1-worker-5
in parTupledN block, key: null
I am in main @coroutine#3
in either block, key: myValue
I am in ForkJoinPool-1-worker-5
in evalOn block, key: null
Evaluated thread result : ForkJoinPool-1-worker-5 in ForkJoinPool-1-worker-5
in either block after evalOn, key: null
I am in ForkJoinPool-1-worker-3
in parTupledN block after evalOn, key: null
I am in ForkJoinPool-1-worker-3
in parTupledN block after evalOn, key: null
Evaluated either block result : ForkJoinPool-1-worker-5 in ForkJoinPool-1-worker-3
in mdcContext after either block, key: null
in test, key: myValue
r
It seems like there is a bug somewhere then. Can you file an issue and include the code snippets please? thanks!
s
ok. Did you check out the other test as well KtorClientTest ? where
evalOn
hangs when ConnectionRefused is thrown ?
Should I make a new issue for that, or include all in one issue ?
s
Hey @Satyam Agarwal, this is expected but probably not expected..
MDCContext
is not a simple
CoroutineContext
, it's a
ThreadContextElement
which is a type that is hard-wired in the KotlinX library so we cananot add support for it.
https://github.com/satyamagarwal/arrow-issues/blob/26a2adfe6dfc5e920872cef52adafca3585f542e/src/test/kotlin/com/arrow/issues/CoroutinesTest.kt#L95
This can be considered a bug, since
Enviroment
actually requires a
ContinuationInterceptor
as an argument, which
MDCContext
isn't. So we can default back to adding
ComputationPool
by default if the provided
CoroutineContext
isn't a
ContinuationInterceptor
. That would fix the incorrect
thread
reading. The reason for this is that to go back to an original thread you need a dispatching
ContinuationInterceptor
, otherwise that's not possible. Although that still wouldn't solve the issue you're having with
MDCContext
. If known this issue for quite a while, but am unsure how we can solve it best or what we can do about it. Ideally the interface would exist in the Standard libray and so all libraries that want to support it can do so but that's probably not happening soon.
👍 2
s
@simon.vergauwen https://github.com/arrow-kt/arrow-fx/issues/304 I have added 2 more test which do not use MDC context at all, and yet do wrong thread reading. Please check them out and see if what I am reporting is is correct 🙂 https://github.com/arrow-kt/arrow-fx/issues/305 Is another issue which is the same repo I created, can you look at this as well please ?
👍 1
s
I'll comment on the issues, and we can discuss it further there!
❤️ 2