From bb22ae6c0b59e451043f59d27e8cfdceb413effa Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Wed, 13 Apr 2022 18:16:54 +0300 Subject: [PATCH] Duct-tape fix for #2930 --- kotlinx-coroutines-core/jvm/src/CoroutineContext.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kotlinx-coroutines-core/jvm/src/CoroutineContext.kt b/kotlinx-coroutines-core/jvm/src/CoroutineContext.kt index e08b805295..34f245ede0 100644 --- a/kotlinx-coroutines-core/jvm/src/CoroutineContext.kt +++ b/kotlinx-coroutines-core/jvm/src/CoroutineContext.kt @@ -181,6 +181,14 @@ internal actual class UndispatchedCoroutineactual constructor ( */ private var threadStateToRecover = ThreadLocal>() + init { + // TODO explain this + if (uCont.context[ContinuationInterceptor] !is CoroutineDispatcher) { + val values = updateThreadContext(context, null) + threadStateToRecover.set(context to values) + } + } + fun saveThreadContext(context: CoroutineContext, oldValue: Any?) { threadStateToRecover.set(context to oldValue) }