# The Ghost Work Left Behind by Cancelled Coroutines

DevFeed: [The Ghost Work Left Behind by Cancelled Coroutines](<https://devfeed.tech/articles/the-ghost-work-left-behind-by-cancelled-coroutines-89749.md>)

Original publisher: [Read original article](<https://proandroiddev.com/the-ghost-work-left-behind-by-cancelled-coroutines-a892bd467a6b?source=rss----c72404660798---4>)

Author: Rohan Maity | RotBolt

Published: 2026-10-18T19:56:04Z

Content type: article

Language: en

Sources: [ProAndroidDev](<https://devfeed.tech/sources/proandroiddev-medium.md>)

Topics: [cancellation](<https://devfeed.tech/topics/cancellation.md>), [Coroutines](<https://devfeed.tech/topics/coroutines.md>), [Exception handling](<https://devfeed.tech/topics/exception-handling.md>), [Structured concurrency](<https://devfeed.tech/topics/structured-concurrency.md>), [suspend function](<https://devfeed.tech/topics/suspend-function.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [bluetooth](<https://devfeed.tech/tags/bluetooth.md>), [bridges](<https://devfeed.tech/tags/bridges.md>), [cancellations](<https://devfeed.tech/tags/cancellations.md>), [coroutine](<https://devfeed.tech/tags/coroutine.md>), [coroutines](<https://devfeed.tech/tags/coroutines.md>), [coroutinescope](<https://devfeed.tech/tags/coroutinescope.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [kotlin-coroutines](<https://devfeed.tech/tags/kotlin-coroutines.md>), [lifecycle](<https://devfeed.tech/tags/lifecycle.md>), [telemetry](<https://devfeed.tech/tags/telemetry.md>)

## AI overview

Kotlin coroutine cancellation is cooperative, so failures occur when code catches CancellationException as an ordinary error, callback bridges fail to cancel underlying requests, blocking calls ignore cancellation, or work runs in scopes without a clear owner. The excerpt links these gaps to misleading error logs and empty results, hanging or stale workflows, wasted IO capacity, Bluetooth work surviving disconnects, and saves lost during logout. It recommends rethrowing cancellation, using cancellable bridges that cancel their requests, preferring suspend APIs (or runInterruptible for interruptible JVM calls), assigning scopes to lifecycle owners, and sequencing critical saves and logout in one coroutine. It also distinguishes timeout-as-error from expected timeout, and notes that a Mutex serializes sends without guaranteeing callback arrival order. The review questions suggest where runtime tracing may help; static review cannot prove that a pattern caused an incident.

## Source excerpt

Lessons from a production Android codebase Cancellation in Kotlin Coroutines looks simple: cancel the Job, and the coroutine stops. In production, it is rarely that clean. Cancellation is cooperative. Every suspend function, exception handler, callback bridge and child scope must carry the signal. Break one boundary, and work may continue after its owner is gone. We saw the result in production: false error logs, empty results, stale Bluetooth work and a final save lost during logout. Nothing crashed. The app simply continued with the wrong state. Cancellation is cooperative Kotlin uses CancellationException to stop a coroutine. Functions such as delay and await check the Job and throw when it is cancelled. val job = scope.launch { delay(5_000) updateState() } job.cancel() Here, delay observes cancellation, so updateState is not called. Regular Kotlin code does not check automatically. It keeps running until the next cancellation point. When cancellation becomes a failure return try { repository.fetchNotifications() } catch (error: Exception) { logger.error("Failed to load notifications", error) emptyList() } If the user leaves the screen, viewModelScope is cancelled and fetchNotifications throws CancellationException. The broad catch records a normal lifecycle event as a failure. It also returns emptyList, so the caller cannot distinguish cancellation from a successful query with no data. runCatching has the same problem because it also catches CancellationException. Rethrow cancellation before handling other failures. catch (error: CancellationException) { throw error } catch (error: Exception) { logger.error("Failed to load notifications", error) emptyList() } In production, normal navigation becomes error telemetry. Empty values can appear as missing documents, notifications or time cards. Support sees missing data while the app reports a completed request. Callback bridges can outlive the caller suspend fun loadMessages() = suspendCoroutine { continuation -> ch