Skip to content

Pass CancelSignal to in-process HeapAnalyzerWorker - #3021

Open
mayokunyusuf wants to merge 1 commit into
square:mainfrom
mayokunyusuf:fix/workmanager-heap-analyzer-cancellation
Open

mayokunyusuf wants to merge 1 commit into
square:mainfrom
mayokunyusuf:fix/workmanager-heap-analyzer-cancellation

Conversation

@mayokunyusuf

Copy link
Copy Markdown

When JobScheduler stops an expedited job running HeapAnalyzerWorker (e.g. on Android 12–16 after timeout or doze), WorkManager reschedules the work while the current doWork() continues running. Because HeapAnalyzerWorker was not checking isStopped or passing a CancelSignal, multiple full heap analyses could run concurrently in the same process, often ending in OutOfMemory.

This mirrors the pattern already used in RemoteHeapAnalyzerWorker:

  • Pass CancelSignal to runAnalysisBlocking checking isStopped
  • Catch CanceledException, log the cancellation, and return Result.retry()
  • Do not send HeapAnalysisDone or progress events when stopped

Closes #3019.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WorkManagerHeapAnalyzer analyzes the same heap dump several times, concurrently, when JobScheduler stops the expedited job

1 participant