[devkit debugger] Catch ObjectCollectedException and drop threads that were collected

GitOrigin-RevId: dabbe5bd6ab19c34d92bf2976e18c15374fca8d6
This commit is contained in:
Maksim Zuev
2025-05-14 18:28:55 +02:00
committed by intellij-monorepo-bot
parent 274e45004c
commit 531e3b1667

View File

@@ -72,8 +72,9 @@ private class SessionThreadsData() {
fun setNonCancellableSection(suspendContext: SuspendContextImpl) {
try {
if (!isPCEAdjustmentEnabled(suspendContext)) return
val thread = suspendContext.thread ?: return
val state = getOrCreateThreadState(suspendContext) ?: return
state.setNonCancellable(suspendContext, true)
setNonCancelableSafe(state, thread, suspendContext, true)
}
catch (e: Exception) {
if (logIncorrectSuspendState(e)) return
@@ -89,9 +90,9 @@ private class SessionThreadsData() {
if (!isPCEAdjustmentEnabled(suspendContext)) return
val pausedThreads = suspendContext.debugProcess.suspendManager.pausedContexts
.mapNotNull { it.thread }
.mapNotNull { threadStates[it] }
for (state in pausedThreads) {
state.setNonCancellable(suspendContext, false)
for (thread in pausedThreads) {
val state = threadStates[thread] ?: continue
setNonCancelableSafe(state, thread, suspendContext, false)
}
}
catch (e: Exception) {
@@ -100,6 +101,18 @@ private class SessionThreadsData() {
}
}
private fun setNonCancelableSafe(
state: ThreadState, thread: ThreadReferenceProxyImpl,
suspendContext: SuspendContextImpl, value: Boolean,
) {
try {
state.setNonCancellable(suspendContext, value)
}
catch (_: ObjectCollectedException) {
threadStates.remove(thread)
}
}
/**
* Get a reference to the [com.intellij.openapi.progress.Cancellation.DebugNonCancellableState] instance
* bounded to the current thread.