-
Notifications
You must be signed in to change notification settings - Fork 527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow coroutines to fail without destabilizing the app #1741
Comments
NB: I suspect this is the reason we were seeing the app stop working when priming was enabled and a failure was encountered. We probably have seen this in a few places without realizing what the underlying cause was. This fix should significantly improve the stability of the app. |
Also, per SupervisorJob documentation a child failure does not affect other children, so some thought needs to be put into how to handle failures in a chained DataProvider case (or even a standard DataProvider suspend function calling other suspend functions, triggering the creation of child coroutines). |
Also: the AsyncResult part of DataProviders may be partly hiding this by aggressively catching exceptions to propagate exceptions. |
For context, I discovered this when trying to implement a CoroutineExecutorService for interop with Java services that needs to rely on ExecutorServices for async operations and that we want to coordinate with our test coroutine dispatchers (e.g. Glide). |
https://kotlinlang.org/docs/reference/coroutines/exception-handling.html#supervision-scope may be a better way to go in general since it lets us hook into |
Actually, it occurs to me all we might need to do is ensure there are different scopes for each independent thing that we want to execute. I think that better fits the paradigm for structured concurrency. |
Is your feature request related to a problem? Please describe.
When coroutines fail, they trigger their outer coroutine scope to enter a failure state. This is unexpected: it results in background failures causing all subsequent background tasks to stay failing preventing the app from working correctly anymore.
Describe the solution you'd like
We should:
For the most part, background execution happens via DataProviders, so this solution probably just needs to be built into
NotifiableAsyncLiveData
. We actually do want failures of children coroutines to trigger an outright failure of the job (including across transformed or combined data providers), but we don't want an independent background DataProvider operation to trigger a failure in an unrelated DataProvider.Describe alternatives you've considered
SupervisorJob seems to be the mechanism invented for this purpose. Two alternatives might be:
Both of these approaches seem harder & more involved than leveraging SupervisorJob.
Additional context
Lots of reading material on the issue:
The text was updated successfully, but these errors were encountered: