Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import java.nio.file.Path
import java.nio.file.Paths
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.TimeUnit

@Service(Service.Level.PROJECT)
class ExternalAcpAgentService(private val project: Project) {
Expand Down Expand Up @@ -134,7 +135,11 @@ class ExternalAcpAgentService(private val project: Project) {
}

fun closeSession(sessionId: String) {
states.remove(sessionId)?.close()
states.remove(sessionId)?.let { state ->
scope.launch {
state.close()
}
}
sessionSetupMutexes.remove(sessionId)
}

Expand Down Expand Up @@ -850,8 +855,23 @@ class ExternalAcpAgentService(private val project: Project) {
}

fun close() {
protocol.close()
process.destroy()
shutdownProcess()
runCatching {
protocol.close()
}.onFailure { throwable ->
logger.warn("Failed to close ACP protocol for ${preset.displayName}", throwable)
}
}

private fun shutdownProcess() {
runCatching {
process.destroy()
if (!process.waitFor(500, TimeUnit.MILLISECONDS)) {
process.destroyForcibly()
}
}.onFailure { throwable ->
logger.warn("Failed to stop ACP process for ${preset.displayName}", throwable)
}
}
}

Expand Down