RUBY-34028 use lockMaybeCancellable in TextMateServiceImpl#ensureInitialized

Read/write actions are sometimes dependent on data from text mate service, as it helps determine file types. However, if another thread is already initializing the service, then the current thread may block without cancellation checks until initialization is complete. Now, it's possible to check for cancellation while waiting on the lock.


(cherry picked from commit 4739498b0dea1389a89fe041e6fbd8001f6d3220)

IJ-CR-161773

GitOrigin-RevId: a0d7878666bd9d29a35faef0da57e0bd8dbfbdd1
This commit is contained in:
Henry Wylde
2025-05-08 23:14:39 +00:00
committed by intellij-monorepo-bot
parent 6663d72383
commit 067fef4544
@@ -15,6 +15,7 @@ import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.IntellijInternalApi
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.util.text.Strings
import com.intellij.util.progress.lockMaybeCancellable
import kotlinx.coroutines.CoroutineScope
import org.jetbrains.annotations.NonNls
import org.jetbrains.annotations.TestOnly
@@ -239,7 +240,7 @@ class TextMateServiceImpl(private val myScope: CoroutineScope) : TextMateService
private fun ensureInitialized() {
if (!isInitialized) {
registrationLock.lock()
registrationLock.lockMaybeCancellable()
try {
if (isInitialized) return
registerBundles(fireEvents = false)