From 52eaadcce9f6579a3a9f48cc9fb322fb8a64115a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=96=8C?= Date: Thu, 20 Jul 2023 20:04:19 +0800 Subject: [PATCH 1/2] JobSupport.kt: fix GH!3658 --- kotlinx-coroutines-core/common/src/JobSupport.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kotlinx-coroutines-core/common/src/JobSupport.kt b/kotlinx-coroutines-core/common/src/JobSupport.kt index 0c63b6a4b4..845cdd82c6 100644 --- a/kotlinx-coroutines-core/common/src/JobSupport.kt +++ b/kotlinx-coroutines-core/common/src/JobSupport.kt @@ -349,7 +349,9 @@ 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 + var 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 +653,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 } From 892b17eb72b431df350fb65f03b7d4d64157197e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E6=96=8C?= Date: Thu, 20 Jul 2023 20:08:19 +0800 Subject: [PATCH 2/2] JobSupport.kt: code format --- kotlinx-coroutines-core/common/src/JobSupport.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kotlinx-coroutines-core/common/src/JobSupport.kt b/kotlinx-coroutines-core/common/src/JobSupport.kt index 845cdd82c6..662b40c1c7 100644 --- a/kotlinx-coroutines-core/common/src/JobSupport.kt +++ b/kotlinx-coroutines-core/common/src/JobSupport.kt @@ -349,9 +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. */ - var isCancellation = cause is JobCancellationException && + 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) {