[debugger] RIDER-141781 Review fixes IJ-CR-219419

(cherry picked from commit 53d1fc67fb6a1cbe45f4737ca8ebfed70e6f1f9c)

GitOrigin-RevId: 9de2befa307f4a313cac85dc3fab34e89e933b93
This commit is contained in:
Maksim Zuev
2026-08-21 11:42:42 +00:00
committed by intellij-monorepo-bot
parent f757637a8b
commit fa00552fe4
2 changed files with 33 additions and 13 deletions
@@ -9,10 +9,8 @@ import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.channels.consumeEach
import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.completeWith
import kotlinx.coroutines.launch
import kotlinx.coroutines.selects.select
import kotlinx.coroutines.supervisorScope
/**
@@ -58,22 +56,21 @@ internal class SequentialRpcRequestsExecutor private constructor() {
override suspend fun performRequest() {
if (!result.isActive) return
supervisorScope {
val requestResult = async { request() }
select {
requestResult.onJoin {
result.completeWith(runCatching { requestResult.await() })
}
result.onJoin {
requestResult.cancelAndJoin()
}
try {
supervisorScope {
val requestResult = async { request() }
result.invokeOnCompletion { requestResult.cancel() }
result.completeWith(runCatching { requestResult.await() })
}
}
finally {
result.cancel()
}
}
override fun markUndelivered() {
this.result.cancel()
result.cancel()
}
}
@@ -5,6 +5,7 @@ import com.intellij.platform.debugger.impl.frontend.util.SequentialRpcRequestsEx
import com.intellij.platform.util.coroutines.childScope
import com.intellij.testFramework.LoggedErrorProcessor
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.cancel
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
@@ -155,6 +156,28 @@ internal class SequentialRpcRequestsExecutorTest {
assertTrue(request.isCancelled)
}
@Test
fun `cancelling executor scope cancels running and queued requests`() = runBlocking {
val scope = childScope("SequentialRpcRequestsExecutor")
val executor = SequentialRpcRequestsExecutor.create(scope)
val requestStarted = CompletableDeferred<Unit>()
val runningRequest = executor.submit {
requestStarted.complete(Unit)
awaitCancellation()
}
val queuedRequest = executor.submit {
error("Queued request must not be executed")
}
requestStarted.await()
scope.cancel()
runningRequest.join()
queuedRequest.join()
assertTrue(runningRequest.isCancelled)
assertTrue(queuedRequest.isCancelled)
}
private fun runTest(test: suspend (SequentialRpcRequestsExecutor) -> Unit) = runBlocking {
val scope = childScope("SequentialRpcRequestsExecutor")
val executor = SequentialRpcRequestsExecutor.create(scope)