Repository navigation
fix: the DAP session stays at a stop which comes while an answer, a refusal or a 'continued' event changes it - #2324
Merged
lagergren merged 3 commits intoNov 28, 2026
Conversation
…er to Reverse Continue, Step Back or Reset Frame resumes it IntelliJ doesn't resume the session for Reverse Continue, Step Back or Reset Frame, so the client resumes it once the debug adapter answers, unless the debug adapter said since the request that the program stopped or continued, or another stop suspended the session. The answer is handled on LSP4J's thread, or on the thread which sent the request, such as the EDT, when the debug adapter answered before that thread chained the handling to the request. A stop suspends the session on another thread, once the client has its threads and frames. When the debug adapter answered first, as DAP orders the answer and the 'stopped' event, and the EDT handled the answer late, both checks passed, and the stop could then suspend the session before the EDT's sessionResumed() cleared it: the session showed the program running, without frames, until the next 'stopped' event. The resume and the suspension at a stop are now changes of the session which run one at a time, in the order in which they come (DAPSessionChanges). No thread waits for another: a change runs right away on the thread which brings it, unless another change runs, and then right after it, on that thread. A lock would make the EDT wait for a stop whose listeners may wait for the EDT, as the synchronous refresh of the VFS does when the position of a frame is first computed off the EDT. The clients of a tree of DAP sessions share these changes, as they share the session. The answer still resumes the session before the 'stopped' event which follows it is handled, an answer which comes after a stop still leaves the session there, and a refusal still leaves the session where it was. The new session test makes the EDT handle the answer, which the DAP server sends first, and lets the client handle the stop while the answer resumes the session. Fixes redhat-developer#2322
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2324 +/- ##
==========================================
- Coverage 58.64% 58.61% -0.04%
==========================================
Files 848 849 +1
Lines 36679 36704 +25
Branches 5763 5765 +2
==========================================
+ Hits 21510 21513 +3
- Misses 12170 12188 +18
- Partials 2999 3003 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…s while the session is suspended again When the debug adapter refuses a Resume or a step, which IntelliJ resumed the session for, the client suspends the session again at the stop where the program still is, unless the session ended or another stop suspended it meanwhile. It looked at the session and then suspended it, on the thread which handles the refusal. Another stop, such as one of another thread or of a child session, which suspended the session on another thread between the two, was then replaced by the stop of the refused request: the session showed that older stop, whose values could no longer be set, instead of the newer one. The suspension again is now a change of the session (DAPSessionChanges), as the suspension at a stop is. A stop which comes while the session is looked at suspends it afterwards, and the session stays at that stop. A stop which suspended the session before still leaves it there, and a session which ended is still left as it is. The new test lets another stop come on another thread as the session is suspended again. It fails when the changes run at once on the thread which brings them, as before. Refs redhat-developer#2322
…ad which comes while the event resumes it A 'continued' event resumes the session when the session is suspended at a stop of the client which received it, and the event continued the thread of that stop. The client looked at the session and then resumed it, on LSP4J's thread. A stop which the event didn't continue, such as one of another thread or of a child session, and which suspended the session on another thread between the two, was then undone: the session showed the program running, without frames, although it was stopped there, until the next 'stopped' event. The resume is now a change of the session (DAPSessionChanges), as the suspension at a stop is. Such a stop suspends the session once the event resumed it, and the session stays there. An event which continued the thread of the stop where the session is still resumes it, and an event of another thread still leaves the session suspended, and shows the threads again. The new test lets a stop of another thread come on another thread as the event resumes the session. It fails when the changes run at once on the thread which brings them, as before. Refs redhat-developer#2322
This was referenced Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2322
Follow-up to #2321, for 0.30.2.
#2321 made an answer to Reverse Continue, Step Back or Reset Frame leave the session alone once the debug adapter had
reported a stop since the request. One window remained, as CodeRabbit noted on #2321:
sessionResumed()is still running.The first commit closes that window. The second and third commits close the two windows of the same shape that it
left, which the first version of this PR listed as not covered: the suspension again after a refused Resume or step,
and the resume at a
continuedevent. Three commits, for a rebase merge.Behaviour change
stopped, and the EDT handled the answer late, the stop could suspend the session while the answer resumed it. The resume then cleared the stop, and the session showed the program running, with no frames, until the nextstoppedevent.continuedevent looked at the session and then resumed it. A stop that the event didn't continue, such as one of another thread or of a child session, that suspended the session between the two was undone: the session showed the program running, without frames, until the nextstoppedevent.Design: a serial executor, not a lock
The new
DAPSessionChangesis anExecutorof about 15 lines of logic:These go through it:
resumeWhenAnswered, the check of the suspend context andsessionResumed();suspend(), with itspositionReached,resumeIfContinuedand hints;breakpointReached, so that a breakpoint with a log expression is covered too;suspendAgain, after a refused Resume or step, the check of the session andpositionReached;continued, the check of the session andsessionResumed(), or the refresh of the threads for anevent of another thread.
DAPDropFrameHandler.restartFramepasses the executor along. The epoch check of #2321 stays where it was, on the threadthat handles the answer.
Why not a lock. Under a lock, the stop's thread would hold it inside
positionReached, and two things there waitfor other threads:
positionReachedInternalcallsgetTopFramePosition(), thenDAPStackFrame.getSourcePosition(), thenLocalSourceFiles.findFile. Off the EDT, that refreshes the file synchronously, and waits for the EDT's write action.An EDT that waited for the lock, to resume after a late answer, would then deadlock with it.
positionReachedandbreakpointReachedalso takes a read action(
setBreakpointsDisabledTemporarily).No thread waits for the executor, so there is no such cycle, whatever a listener does.
The listeners that run inside a change were audited for 2024.2, and for 2026.3, where the split debugger is
always on:
inline only when already on it;
XBreakpointManagerImpl's own lock, without the EDT.trySend), and nothing on the calling threadwaits for the EDT.
A trade-off for reviewers: a queued change runs on whichever thread is running changes, which can be the EDT,
LSP4J's thread or a pool thread. So a resume may run on a pool thread, or a stop's suspension on the EDT. These session
calls already run on those threads today:
suspendAgainrunspositionReachedon the EDT or on LSP4J's thread;breakpointReachedon LSP4J's thread;resumeIfContinuedrunssessionResumedon a pool thread;continuedevent runssessionResumedandrebuildViewson LSP4J's thread.On the EDT,
DAPStackFrame.getSourcePositiontakes its existing branch that defers the position.Tests of the first commit
The new
DAPReverseDebuggingSessionTest.testAStopHandledWhileTheAnswerToReverseContinueResumesTheSessionOnTheEDTSuspendsTheSessionOnceItResumedforces the order, without fixed sleeps or hooks in the product:
beforeSessionResume, the test sendsstopped, and waits until the client has handled the stop's frames.shows as stopped.
expected:<[resumed, suspended in the frame 2]> but was:<[suspended in the frame 2, resumed]>New unit tests:
DAPSessionChangesTest, 3 tests;DAPClientReverseExecutionTest, a stop during the resume runs after it, and an answer during another stop leavesthe session at that stop;
DAPClientBreakpointReachedTest, a breakpoint stop that comes during another change is deferred.All headless, with the counts from the JUnit XMLs, for 36 test classes: #2321's 6, the new class, every class that
covers the stop chain or
positionReached, and the session-tree, pause and single-thread-step tests:Tests of the second and third commits
The two windows are on LSP4J's thread, which also handles the frames of a stop, so a session test can't hold that
thread inside the window as the first commit's test holds the EDT. One unit test per window forces the order instead,
with a session proxy: another thread brings a stop's suspension in the window and returns at once.
DAPClientSuspendAgainTest.aStopWhichComesWhileTheSessionIsSuspendedAgainSuspendsItAfterwardsAndTheSessionStaysThereexpected: <[the stop of the refused request, the next stop]> but was: <[the next stop, the stop of the refused request]>DAPClientContinuedTest.aStopOfAnotherThreadWhichComesWhileTheEventResumesTheSessionSuspendsItAfterwardsAndTheSessionStaysThereexpected: <[resumed, suspended]> but was: <[suspended, resumed]>Headless, with the counts from the JUnit XMLs, for the 15 classes that cover the changes of the session, refusals,
continuedevents and the run states of the threads2:The second commit compiles on its own, tests included.
Not covered
doResume, on the EDT) before LSP4IJ sends therequest, so the step's own stop always comes after it. An unrelated stop already on its way, such as one of another
thread, can still interleave with that
doResume. The session then recovers at the step's own stop. The executorcan't cover this, as
doResumeruns inside IntelliJ.continuedevent of another thread (selectStoppedThread): itchecks the session on the EDT and then calls
setCurrentStackFrame, which in 2024.2 checks only that the sessionhas a suspend context, not which one. A stop that suspends the session between the two would show a frame of the
earlier stop as the current one. The selection must run on the EDT, and the executor may run a change on another
thread, so it doesn't fit there.
threads before this change.
Footnotes
DAPSessionChanges.executepatched to run each change at once on the calling thread, as the code did before.All other tests of both classes pass with it. ↩
DAPClientBreakpointReachedTest,DAPClientContinuedTest,DAPClientReverseExecutionTest,DAPClientSuspendAgainTest,DAPContinuedEventSessionTest,DAPContinuedEventsTest,DAPDropFrameHandlerTest,DAPExecutionEpochTest,DAPOutputLocationSessionTest,DAPRefusedResumeSessionTest,DAPReverseDebuggingSessionTest,DAPSessionChangesTest,DAPSetValueInAStoppedThreadSessionTest,DAPThreadRunStateSessionTest,DAPThreadRunStatesTest. ↩