Browse Source

fix: implement proper executor shutdown for CRITICAL-004

- Add proper ocrExecutor lifecycle management in ScreenCaptureService.onDestroy()
- Use awaitTermination() with 5-second timeout before forcing shutdownNow()
- Handle InterruptedException with proper thread interrupt restoration
- Verified temporary executors in YOLOOnnxDetector already have proper cleanup
- Prevents thread pool resource leaks and ensures clean service shutdown

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
critical-004-thread-pool-leaks
Quildra 5 months ago
parent
commit
24740c7ff7
  1. 11
      app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt

11
app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt

@ -1254,7 +1254,18 @@ class ScreenCaptureService : Service() {
enhancedFloatingFAB?.hide()
detectionController.clearUICallbacks()
yoloDetector?.release()
// Proper executor shutdown with timeout
ocrExecutor.shutdown()
try {
if (!ocrExecutor.awaitTermination(5, TimeUnit.SECONDS)) {
Log.w(TAG, "OCR executor did not terminate gracefully, forcing shutdown")
ocrExecutor.shutdownNow()
}
} catch (e: InterruptedException) {
Log.w(TAG, "Interrupted while waiting for OCR executor termination")
ocrExecutor.shutdownNow()
Thread.currentThread().interrupt()
}
stopScreenCapture()
}
}
Loading…
Cancel
Save