Skip to content
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

Crash, heap dump missing #1417

Closed
pyricau opened this issue Jun 28, 2019 · 2 comments · Fixed by #1418
Closed

Crash, heap dump missing #1417

pyricau opened this issue Jun 28, 2019 · 2 comments · Fixed by #1418
Milestone

Comments

@pyricau
Copy link
Member

pyricau commented Jun 28, 2019

HeapAnalyzer crashes because the heap dump file passed to the service didn't exist

leakcanary.HeapAnalysisException: java.lang.IllegalArgumentException: File does not exist: /storage/emulated/0/Download/leakcanary-com.squareup.development/f871e570-be04-4368-9621-c964c27671e8_pending.hprof
        at leakcanary.HeapAnalyzer.checkForLeaks(HeapAnalyzer.kt:93)
        at leakcanary.internal.HeapAnalyzerService.onHandleIntentInForeground(HeapAnalyzerService.kt:49)
        at leakcanary.internal.ForegroundService.onHandleIntent(ForegroundService.kt:55)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:78)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:67)
Caused by: java.lang.IllegalArgumentException: File does not exist: /storage/emulated/0/Download/leakcanary-com.squareup.development/f871e570-be04-4368-9621-c964c27671e8_pending.hprof
        at leakcanary.HeapAnalyzer.checkForLeaks(HeapAnalyzer.kt:90)
        at leakcanary.internal.HeapAnalyzerService.onHandleIntentInForeground(HeapAnalyzerService.kt:49)
        at leakcanary.internal.ForegroundService.onHandleIntent(ForegroundService.kt:55)
        at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:78)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:67)

Not sure how this can happen. Worth noticing that 2 seconds before we were successfully parsing and handling a hprof (same? another one?)

The latest release of leakcanary does not block if an analysis is in progress, so there might be concurrency issue or old cleanup code that's too aggressive.

@pyricau
Copy link
Member Author

pyricau commented Jun 28, 2019

When we reach the limit of hprof files, we remove the oldest.

The analyzer service is serial, and each hprof is renamed where handled, it's very likely that this resets lastModified to a more recent value and therefore the oldest hprof is the one that hasn't been handled yet, leading to this error.

Fix is probably to reset lastModified to the same date after the move (file.setLastModified())

@pyricau pyricau added this to the 2.0 Next Release milestone Jun 28, 2019
@pyricau
Copy link
Member Author

pyricau commented Jun 28, 2019

I haven't been able to repro, last modified doesn't seem to change on my emulator. I'm not sure what else this could be, so will apply the enforcement of last modified.

pyricau added a commit that referenced this issue Jun 28, 2019
pyricau added a commit that referenced this issue Jun 28, 2019
pyricau added a commit that referenced this issue Jun 28, 2019
* Added LeakCanary.Config.maxStoredHeapDumps (default 7) to enabling configuring how many hprof files are retained.
* Added LeakCanary.Config.requestWriteExternalStoragePermission (default false) to stop having those pesky double LeakCanary notifications on first leak for most users.
* Added tracking of why files were removed in case #1417 happens again.
pyricau added a commit that referenced this issue Jun 28, 2019
* Added LeakCanary.Config.maxStoredHeapDumps (default 7) to enabling configuring how many hprof files are retained.
* Added LeakCanary.Config.requestWriteExternalStoragePermission (default false) to stop having those pesky double LeakCanary notifications on first leak for most users.
* Added tracking of why files were removed in case #1417 happens again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant