Skip to content

Commit 9b7ffec

Browse files
authored
fix(amazonq): force exit Flare if it does not quickly exit nicely (#5879)
if Flare is stuck then both IDE/Flare will never exit and user must force-exit the IDE process using system tools
1 parent 1fe2448 commit 9b7ffec

File tree

1 file changed

+13
-6
lines changed
  • plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp

1 file changed

+13
-6
lines changed

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import com.intellij.openapi.util.Key
2525
import com.intellij.openapi.util.SystemInfo
2626
import com.intellij.util.EnvironmentUtil
2727
import com.intellij.util.io.DigestUtil
28-
import com.intellij.util.io.await
2928
import com.intellij.util.net.HttpConfigurable
3029
import com.intellij.util.net.JdkProxyProvider
3130
import com.intellij.util.net.ssl.CertificateManager
@@ -39,6 +38,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
3938
import kotlinx.coroutines.flow.asSharedFlow
4039
import kotlinx.coroutines.flow.map
4140
import kotlinx.coroutines.future.asCompletableFuture
41+
import kotlinx.coroutines.future.await
4242
import kotlinx.coroutines.isActive
4343
import kotlinx.coroutines.launch
4444
import kotlinx.coroutines.runBlocking
@@ -717,15 +717,22 @@ private class AmazonQServerInstance(private val project: Project, private val cs
717717
override fun dispose() {
718718
if (!launcherFuture.isDone) {
719719
try {
720-
languageServer.apply {
721-
shutdown().thenRun { exit() }
722-
}
720+
// otherwise can deadlock waiting for frozen flare process
721+
cs.launch {
722+
languageServer.apply {
723+
withTimeout(2000) {
724+
shutdown().await()
725+
exit()
726+
}
727+
}
728+
}.asCompletableFuture()
729+
.get(3000, TimeUnit.MILLISECONDS)
723730
} catch (e: Exception) {
724731
LOG.warn(e) { "LSP shutdown failed" }
725-
launcherHandler.destroyProcess()
732+
launcherHandler.killProcess()
726733
}
727734
} else if (!launcherHandler.isProcessTerminated) {
728-
launcherHandler.destroyProcess()
735+
launcherHandler.killProcess()
729736
}
730737
}
731738

0 commit comments

Comments
 (0)