Properly handle scoped coroutines in JobSupport.cancelParent
diff --git a/kotlinx-coroutines-core/common/src/JobSupport.kt b/kotlinx-coroutines-core/common/src/JobSupport.kt
index 63e34fd..d7ca5f6 100644
--- a/kotlinx-coroutines-core/common/src/JobSupport.kt
+++ b/kotlinx-coroutines-core/common/src/JobSupport.kt
@@ -326,6 +326,9 @@
* may leak to the [CoroutineExceptionHandler].
*/
private fun cancelParent(cause: Throwable): Boolean {
+ // Is scoped coroutine -- don't propagate, will be rethrown
+ if (isScopedCoroutine) return true
+
/* CancellationException is considered "normal" and parent usually is not cancelled when child produces it.
* This allow parent to cancel its children (normally) without being cancelled itself, unless
* child crashes and produce some other exception during its completion.
@@ -337,8 +340,6 @@
return isCancellation
}
- // Is scoped coroutine -- don't propagate, will be rethrown
- if (isScopedCoroutine) return isCancellation
// Notify parent but don't forget to check cancellation
return parent.childCancelled(cause) || isCancellation
}