ADFA-4010: close indexing services on background thread#1308
Conversation
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughRelease NotesFeatures & Improvements
Technical Changes
Risks & Considerations
WalkthroughIndexingServiceManager.close() is rewritten to concurrently shut down registered services and the registry with a 10s per-target timeout, await join of close jobs, then cancel remaining work and clear state. ProjectManagerImpl updates an import to use IndexingServiceManager. ChangesGraceful service shutdown with timeouts
Sequence DiagramsequenceDiagram
participant Caller as IndexingServiceManager.close()
participant Service as IndexingService
participant Registry as ServiceRegistry
participant Scope as CoroutineScope
Caller->>Service: launch close() with withTimeoutOrNull(SERVICE_CLOSE_TIMEOUT)
Caller->>Registry: launch registry.close() with timeout
Caller->>Caller: collect close jobs
Caller->>Caller: runCatching { joinAll(closeJobs, registryJob) }
Caller->>Scope: scope.coroutineContext.cancelChildren() (if needed)
Caller->>Caller: clear services, set initialized = false, log shutdown
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lsp/indexing/src/main/kotlin/org/appdevforall/codeonthego/indexing/service/IndexingServiceManager.kt (1)
143-157:⚠️ Potential issue | 🟠 Major | ⚡ Quick winFinish async close work before clearing manager state.
Lines 153-157 run immediately after the jobs are scheduled, not after they finish. That lets
service.close()raceregistry.close()and makes the final shutdown log fire too early.Suggested fix
override fun close() { log.info("Shutting down indexing services") + initialized = false @@ scope.launch { runCatching { joinAll(*cancellationJobs.toTypedArray()) } .onFailure { err -> log.error("Failed to close indexing services", err) } // Cancel in-flight work scope.coroutineContext.cancelChildren() + + services.clear() + registry.close() + log.info("Indexing services shut down") } - - services.clear() - registry.close() - initialized = false - - log.info("Indexing services shut down") }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lsp/indexing/src/main/kotlin/org/appdevforall/codeonthego/indexing/service/IndexingServiceManager.kt` around lines 143 - 157, The shutdown schedules a coroutine with scope.launch but then immediately clears state (services.clear, registry.close, initialized=false) and logs shutdown before the async work finishes; change the logic to wait for the launched coroutine to complete before mutating state—either by making the surrounding function suspend and using runCatching { joinAll(*cancellationJobs.toTypedArray()); scope.coroutineContext.cancelChildren() } directly, or by capturing the Job returned from scope.launch (the launch call around joinAll) and calling job.join() (or awaiting it in a runBlocking) before calling services.clear, registry.close, setting initialized = false and logging; ensure the join/await happens on the same coroutine scope so service.close()/registry.close() cannot race with state clearing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@lsp/indexing/src/main/kotlin/org/appdevforall/codeonthego/indexing/service/IndexingServiceManager.kt`:
- Around line 130-136: The catch block inside the
withTimeoutOrNull(SERVICE_CLOSE_TIMEOUT) around service.close() is catching
CancellationException and masking timeout cancellations; update the exception
handling in IndexingServiceManager (the withTimeoutOrNull block that calls
service.close() and logs via log.debug/log.error) to rethrow
CancellationException (or specifically catch CancellationException first and
throw it) and only handle other exceptions (e.g., Exception) for logging, so a
timeout cancellation propagates as intended to the timeout path.
---
Outside diff comments:
In
`@lsp/indexing/src/main/kotlin/org/appdevforall/codeonthego/indexing/service/IndexingServiceManager.kt`:
- Around line 143-157: The shutdown schedules a coroutine with scope.launch but
then immediately clears state (services.clear, registry.close,
initialized=false) and logs shutdown before the async work finishes; change the
logic to wait for the launched coroutine to complete before mutating
state—either by making the surrounding function suspend and using runCatching {
joinAll(*cancellationJobs.toTypedArray());
scope.coroutineContext.cancelChildren() } directly, or by capturing the Job
returned from scope.launch (the launch call around joinAll) and calling
job.join() (or awaiting it in a runBlocking) before calling services.clear,
registry.close, setting initialized = false and logging; ensure the join/await
happens on the same coroutine scope so service.close()/registry.close() cannot
race with state clearing.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cf20a36b-6c35-4403-84c7-b4b729134cf7
📒 Files selected for processing (2)
lsp/indexing/src/main/kotlin/org/appdevforall/codeonthego/indexing/service/IndexingServiceManager.ktsubprojects/projects/src/main/java/com/itsaky/androidide/projects/ProjectManagerImpl.kt
💤 Files with no reviewable changes (1)
- subprojects/projects/src/main/java/com/itsaky/androidide/projects/ProjectManagerImpl.kt
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
jatezzz
left a comment
There was a problem hiding this comment.
Take a look at coderabbit comment.
Signed-off-by: Akash Yadav <akashyadav@appdevforall.org>
See ADFA-4010 for more details.