Skip to content

Commit b37ca3a

Browse files
committed
Properly handle scoped coroutines in JobSupport.cancelParent
1 parent 684a97b commit b37ca3a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

kotlinx-coroutines-core/common/src/JobSupport.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
326326
* may leak to the [CoroutineExceptionHandler].
327327
*/
328328
private fun cancelParent(cause: Throwable): Boolean {
329+
// Is scoped coroutine -- don't propagate, will be rethrown
330+
if (isScopedCoroutine) return true
331+
329332
/* CancellationException is considered "normal" and parent usually is not cancelled when child produces it.
330333
* This allow parent to cancel its children (normally) without being cancelled itself, unless
331334
* child crashes and produce some other exception during its completion.
@@ -337,8 +340,6 @@ public open class JobSupport constructor(active: Boolean) : Job, ChildJob, Paren
337340
return isCancellation
338341
}
339342

340-
// Is scoped coroutine -- don't propagate, will be rethrown
341-
if (isScopedCoroutine) return isCancellation
342343
// Notify parent but don't forget to check cancellation
343344
return parent.childCancelled(cause) || isCancellation
344345
}

0 commit comments

Comments
 (0)