markzhai / markzhai/AndroidPerformanceMonitor

[Bug] Static fileIoExecutor causes thread leak and StrictMode violations

Open
#154 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
6.7k
Forks
1k
PR merge metrics
No merged PRs in 30d

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
1. Static Resource: The executor is defined as private static final at line 133.

2. 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.

3. 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
1. Thread Leak: The thread named "File-IO" persists indefinitely, leaking resources.

2. 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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

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.

Assessment

Tech stack
android, java
Domain
mobile, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.