Fix RejectedExecutionException crash on ViewModel teardown#432
Open
patrickrb wants to merge 1 commit into
Open
Fix RejectedExecutionException crash on ViewModel teardown#432patrickrb wants to merge 1 commit into
patrickrb wants to merge 1 commit into
Conversation
A late deep-decode pass can deliver afterDecode() on a background decode thread after MainViewModel.onCleared() has already shut getQTHThreadPool / sendWaveDataThreadPool down. The raw execute() on a terminated pool throws RejectedExecutionException (default AbortPolicy), which is uncaught on the decode thread and takes the whole process down. Observed crash (07-05): RejectedExecutionException: Task MainViewModel$GetQTHRunnable rejected from ThreadPoolExecutor[Terminated] at MainViewModel.afterDecode Guard all three pool submissions behind SafeExecutor.tryExecute(), a small top-level helper that fast-paths on isShutdown() and swallows the RejectedExecutionException race, dropping the task instead of crashing. Extracted so it is unit-testable without Android (pure JUnit + Truth). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #432 +/- ##
============================================
+ Coverage 21.47% 21.57% +0.09%
- Complexity 133 140 +7
============================================
Files 150 154 +4
Lines 19755 19945 +190
Branches 2909 2947 +38
============================================
+ Hits 4243 4303 +60
- Misses 15344 15474 +130
Partials 168 168
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
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.
Problem
Pulled from a crashing device (
debug.log+ logcat crash buffer, 07-05). One of two distinct app crashes found:A late deep-decode pass delivers
afterDecode()on a background decode thread afterMainViewModel.onCleared()has shutgetQTHThreadPool/sendWaveDataThreadPooldown (ViewModel destroyed on activity teardown/recreate). The rawexecute()on the terminated pool throwsRejectedExecutionException(defaultAbortPolicy), which is uncaught on the decode thread and crashes the process.Fix
New
SafeExecutor.tryExecute(pool, task)helper: fast-paths onisShutdown(), and wrapsexecute()in atry/catch (RejectedExecutionException)to cover the check→execute race withonCleared(). Drops the task and returnsfalseinstead of throwing.Wired into all three submit sites in
MainViewModel(1×getQTHThreadPool, 2×sendWaveDataThreadPool).Tests
SafeExecutorTest(pure JUnit + Truth, no Robolectric needed): live-pool execution, shutdown pool,shutdownNow(), null pool, null task.:app:testDebugUnitTestgreen.🤖 Generated with Claude Code