[Bug] Static fileIoExecutor causes thread leak and StrictMode violations
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 52/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- android, java
- Domain
- mobile, performance
Research direction
Start in com/github/moduth/blockcanary/BlockCanary.java by reading the static fileIoExecutor initialization and the stop() lifecycle. Exercise the stop path during integration testing and verify that the File-IO thread is terminated without StrictMode thread-leak warnings.
Written by the indexing model from the issue text.
Description
Description
The BlockCanary class initializes a private static final Executor named fileIoExecutor for handling log zipping and writing. However, this executor is never shut down, even when BlockCanary.stop() is invoked.
Root Cause
-
Static Resource: The executor is defined as private static final at line 133.
-
Missing Lifecycle Management: There is no mechanism to terminate the fileIoExecutor. The stop() method (Line 103) only stops the CPU and Stack samplers but leaves the IO thread pool active.
-
Process-Level Scope: In Android, this static thread persists as long as the application process is alive, which is broader than the lifecycle of the monitoring session.
Impact
-
Thread Leak: The thread named "File-IO" persists indefinitely, leaking resources.
-
StrictMode Violations: This causes StrictMode thread leak warnings (e.g., Detecting explicit GC) during integration testing or when the app attempts to exit cleanly.
Relevant Code
File: com/github/moduth/blockcanary/BlockCanary.java
// Line 133
private static final Executor fileIoExecutor = newSingleThreadExecutor("File-IO");
// Line 103: stop() does not handle the executor
public void stop() {
if (mMonitorStarted) {
// ...
mBlockCanaryCore.stackSampler.stop();
mBlockCanaryCore.cpuSampler.stop();
// fileIoExecutor is left running
}
}
Suggested Fix
Modify the lifecycle of fileIoExecutor so it can be shut down inside the stop() method, or provide an explicit release() API to terminate the underlying thread pool.
- Dominant language
- Java
- Stars
- 6.7k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from markzhai/AndroidPerformanceMonitor
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
markzhai/AndroidPerformanceMonitor#144 · 4 comments · 1 reaction ·
-
Difficulty 5/5 Over a week Newbie friendliness 5/100
markzhai/AndroidPerformanceMonitor#153 · 5 comments · 1 reaction ·
-
这个库希望有人能维护一下 Open
Difficulty 5/5 Over a week Newbie friendliness 15/100
markzhai/AndroidPerformanceMonitor#149 · 5 comments · 3 reactions ·
-
如何保证捕获卡顿堆栈的准确性? Open
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 35/100
markzhai/AndroidPerformanceMonitor#147 · 8 comments ·
All issues in markzhai/AndroidPerformanceMonitor
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100