Skip to content

DAP: serialize the resume after an answer with the suspension of a stop, so that a late-handled answer can't undo a stop #2322

Done

Description

@lagergren

Follow-up to #2320 and #2321.

What remains

#2321 makes the answer to Reverse Continue, Step Back or Reset Frame leave the session alone once the debug adapter
has reported a stop or a continue since the request. That closes the case of #2320, where stopped comes before the
answer.

One narrower window remains, as CodeRabbit noted in #2321:

  1. The answer comes first, the order DAP normally uses, but its handler runs late on the EDT.
  2. The handler checks that the epoch hasn't ended and that the session is still at the old stop, and both checks
    pass.
  3. Before it calls session.sessionResumed(), the stopped event arrives. On a pool thread, the stop fetches the
    threads and the stack, and suspends the session at the new stop.
  4. sessionResumed() then clears that stop.

The session then shows the program running although it is stopped, until the next stopped event. It needs the
whole stop, with two round trips to the debug adapter, to complete in the gap between the check and the resume, so
it should be much rarer than #2320.

How to close it

Make the check-and-resume of DAPClient.resumeWhenAnswered and the stop's suspension (positionReached)
mutually exclusive: one lock, or one serial executor, shared by both. With a lock:

  • either the resume runs first, and the stop suspends the session after it;
  • or the stop runs first, and the resume then finds a new suspend context and does nothing.

Care needed

Both sessionResumed() and positionReached call IntelliJ's debugger listeners synchronously, and the lock would be
held while they run. A listener that waits for another thread that needs the lock would deadlock. Check this on 2024.2,
and with the split debugger of 2026.x.

Test

Force the answer-first order: the answer handled on the EDT, the epoch check passing, and then the stop's
stackTrace released only while the EDT is inside sessionResumed()'s beforeSessionResume. The test needs no
fixed sleeps, as in #2321's test. It should fail without the lock, and pass with it, on 2024.2, 2026.2 and 2026.3.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugdap

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions