Choosing coroutineScope vs supervisorScope for a multi-step deployment pipeline without silent sibling cancellation
0 reputation · 01 Dec 2022, 17:13 UTC
0 reputation · 01 Dec 2022, 17:13 UTC
I'm structuring a Kotlin deployment pipeline as a set of concurrent rollout steps (config push, service restart, health check) using kotlinx.coroutines. The documented behavior is clear in isolation: a failing child in a regular coroutineScope cancels all siblings and propagates the exception, while supervisorScope lets siblings finish and requires each child to handle its own failure.
What's unresolved for me is the failure semantics I actually want. Fail-fast cancellation sounds right when steps share mutable state, but some steps (e.g., draining connections) should complete even if an unrelated step fails. I also need failures to be visible in logs: I understand async children defer exceptions until await(), and CancellationException is never reported to a CoroutineExceptionHandler, so a cancelled deployment could look like a clean shutdown.
Assume a recent stable kotlinx.coroutines release; I'll verify against the exact deployed version.
My questions:
supervisorScope around independent steps inside an outer fail-fast coroutineScope a sound pattern, or does it produce surprising propagation?async children whose results I may not always await, what is the intended way to guarantee their exceptions reach logs?CoroutineExceptionHandler at the supervisor level reliably catch launch-child failures without masking cancellation?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.