From 522b9404d5b1a237cba00611b4b677ec6da8cc20 Mon Sep 17 00:00:00 2001 From: Konstantin Nisht Date: Thu, 18 Jul 2024 09:47:42 +0200 Subject: [PATCH] [platform] IJPL-158412: Do not fill stacktrace on cancellation of `NonBlockingReadAction` GitOrigin-RevId: b415918b261915f230005e9c1cec5428156ec315 --- .../openapi/application/impl/NonBlockingReadActionImpl.java | 4 +++- .../intellij/util/concurrency/CancellationPropagationTest.kt | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/NonBlockingReadActionImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/NonBlockingReadActionImpl.java index 316d49ef0148..fa4b09514cba 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/NonBlockingReadActionImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/NonBlockingReadActionImpl.java @@ -329,7 +329,9 @@ public final class NonBlockingReadActionImpl implements NonBlockingReadAction // We need to abort the job only in the first case, but not in the second one. // Because in the case of `setResult` there can be a UI callback, and we need to cancel Job strictly after the callback finishes. if (!isSucceeded()) { - cancelJob(new CancellationException()); + // we must not create CancellationException here, + // because filling the stacktrace causes performance degradation + cancelJob(null); } cleanupIfNeeded(); return result; diff --git a/platform/platform-tests/testSrc/com/intellij/util/concurrency/CancellationPropagationTest.kt b/platform/platform-tests/testSrc/com/intellij/util/concurrency/CancellationPropagationTest.kt index a5c9b11fa40a..80b088b78763 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/concurrency/CancellationPropagationTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/util/concurrency/CancellationPropagationTest.kt @@ -727,7 +727,7 @@ class CancellationPropagationTest { } @RepeatedTest(1000) - fun `synchronous non-blocking read action is awaited`() = runBlocking { + fun `synchronous non-blocking read action is awaited`() = timeoutRunBlocking { val dummyDisposable = Disposer.newDisposable() var allowedToCompleteRA by AtomicReference(false) val readActionCompletedSemaphore = Semaphore(1) @@ -761,7 +761,7 @@ class CancellationPropagationTest { .submit(executor) } Disposer.dispose(dummyDisposable) - // if NBRA is not properly canceled, we would have a leaking Job, and `blockingContextScope would never finish` + // if NBRA is not properly canceled, we would have a leaking Job, and `blockingContextScope` would never finish job.join() }