From 0ab52a8c9ae9bf6ab8dfb29d7b08bf309bc4ccb6 Mon Sep 17 00:00:00 2001 From: Vladimir Lagunov Date: Fri, 1 Mar 2024 09:58:48 +0100 Subject: [PATCH] IDEA-347969 IJent: IjentProcessWatcher cancels correct coroutine scope when the process suddenly exits GitOrigin-RevId: f7e12317283bb3f28fd829fc2538285c79aac50c --- .../com/intellij/platform/ijent/IjentProcessWatcher.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/ijent/src/com/intellij/platform/ijent/IjentProcessWatcher.kt b/platform/ijent/src/com/intellij/platform/ijent/IjentProcessWatcher.kt index 2b586aa68056..16dd92cd9457 100644 --- a/platform/ijent/src/com/intellij/platform/ijent/IjentProcessWatcher.kt +++ b/platform/ijent/src/com/intellij/platform/ijent/IjentProcessWatcher.kt @@ -15,7 +15,6 @@ import org.jetbrains.annotations.ApiStatus import org.jetbrains.annotations.VisibleForTesting import java.io.IOException import java.util.concurrent.TimeUnit -import kotlin.coroutines.coroutineContext import kotlin.time.Duration.Companion.seconds /** @@ -97,7 +96,7 @@ class IjentProcessWatcher private constructor(internal val process: Process, pri val processWatcher = IjentProcessWatcher(process, lastStderrMessages) coroutineScope.launch(coroutineScope.coroutineNameAppended("$ijentId > exit code awaiter")) { - ijentProcessExitCodeAwaiter(ijentId, processWatcher, lastStderrMessages) + ijentProcessExitCodeAwaiter(coroutineScope, ijentId, processWatcher, lastStderrMessages) } coroutineScope.launch(coroutineScope.coroutineNameAppended("$ijentId > finalizer")) { @@ -145,6 +144,7 @@ private fun logIjentStderr(ijentId: IjentId, line: String) { @OptIn(DelicateCoroutinesApi::class) private suspend fun ijentProcessExitCodeAwaiter( + ijentCoroutineScope: CoroutineScope, ijentId: IjentId, processWatcher: IjentProcessWatcher, lastStderrMessages: MutableSharedFlow, @@ -159,7 +159,7 @@ private suspend fun ijentProcessExitCodeAwaiter( } if (isExitExpected) { - coroutineContext.cancel(CancellationException("The process expectedly exited with code $exitCode")) + ijentCoroutineScope.cancel(CancellationException("The process expectedly exited with code $exitCode")) } else { val message = "The process suddenly exited with the code $exitCode" @@ -178,7 +178,7 @@ private suspend fun ijentProcessExitCodeAwaiter( LOG.error(RuntimeExceptionWithAttachments(message, Attachment("stderr", stderr.toString()))) } } - coroutineContext.cancel(CancellationException(message)) + ijentCoroutineScope.cancel(CancellationException(message)) } }