diff --git a/kotlinx-coroutines-core/common/src/JobSupport.kt b/kotlinx-coroutines-core/common/src/JobSupport.kt index 0c63b6a4b4..662b40c1c7 100644 --- a/kotlinx-coroutines-core/common/src/JobSupport.kt +++ b/kotlinx-coroutines-core/common/src/JobSupport.kt @@ -349,7 +349,8 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren * This allow parent to cancel its children (normally) without being cancelled itself, unless * child crashes and produce some other exception during its completion. */ - val isCancellation = cause is CancellationException + val isCancellation = cause is JobCancellationException && + (cause.job as JobSupport).state.let{it is Finishing && it.isCancelling()} val parent = parentHandle // No parent -- ignore CE, report other exceptions. if (parent === null || parent === NonDisposableHandle) { @@ -651,7 +652,9 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren * may leak to the [CoroutineExceptionHandler]. */ public open fun childCancelled(cause: Throwable): Boolean { - if (cause is CancellationException) return true + if(cause is JobCancellationException && + (cause.job as JobSupport).state.let{it is Finishing && it.isCancelling()}) + return true return cancelImpl(cause) && handlesException }