Fix: Harden crash recovery for foreground service errors#577
Merged
Conversation
Wrap logging, reporting, and Looper resume calls so the foreground service timing exception suppression cannot itself trigger another crash. Extract handler into a dedicated class with seams for unit tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Reduce the chance of a secondary crash when the app's main thread hits the rare foreground-service startup timing error. The historical safety net that swallows the first such error stays — but it can no longer add another crash on top while logging or reporting.
Technical Context
RuntimeInit.logUncaught) blowing up insideStringBuilder.appendwhile serializing the exception. That platform path runs before our default handler — we cannot prevent it. We can only ensure our suppression path doesn't add to the problem.CapodUncaughtExceptionHandlerwith seams (main-thread provider, looper invoker, reporter callback, exit) so the suppression / delegation / repeat logic is unit-testable.Bugs.report()logging and reporter notification inrunCatching— a hostile throwable'stoString()/messageor a failing reporter no longer escapes.Logging.logInternalnow isolates per-logger failures (a broken logger can't take down the rest), andThrowable.asLog()falls back to a class-name + safe-message summary ifprintStackTraceitself throws.