Does SupervisorJob prevent parent cancellation when a child coroutine fails?
0 reputation · 01 May 2026, 10:04 UTC
Structured Concurrency and Exception Propagation
In Kotlin Coroutines, structured concurrency typically ensures that a failure in a child coroutine propagates upward, triggering the cancellation of the parent and all remaining sibling coroutines. This behavior is designed to prevent orphaned tasks when a critical dependency fails.
SupervisorJob Constraints
To decouple this failure propagation, SupervisorJob is often employed. While it is documented that a supervisor does not fail its parent or siblings, the specific interaction between a SupervisorJob and a CoroutineExceptionHandler in a root scope requires clarification to ensure exceptions are handled without crashing the application.
Which mechanism is required to ensure that an uncaught exception in a child of a SupervisorJob is captured without triggering the cancellation of the supervisor itself? Does the CoroutineExceptionHandler need to be defined at the scope level or the individual job level to achieve this?