From 24740c7ff79483f796851ac1990ea858599288f1 Mon Sep 17 00:00:00 2001 From: Quildra Date: Fri, 1 Aug 2025 23:23:46 +0100 Subject: [PATCH] fix: implement proper executor shutdown for CRITICAL-004 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- .../pokegoalshelper/ScreenCaptureService.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt b/app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt index a11fe67..fff0f3a 100644 --- a/app/src/main/java/com/quillstudios/pokegoalshelper/ScreenCaptureService.kt +++ b/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() } } \ No newline at end of file