Skip to content

fix: loads of a DAP source given by reference which run at once ask the debug adapter for its text once - #2264

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/dap-source-loaded-once
Nov 25, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/dap-source-loaded-once

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2263

What

Each load of a source given by reference sent its own source request. Two loads of one reference could run at once:

  • DAPStackFrame.getSourcePosition() creates its position lazily, without a lock. The session publishes a stop before it asks for the top frame's position on the DAP event thread, so the EDT and other threads ask for the same frame at once.
  • A frame loads unless its file holds the text, and the file holds it only once the first answer is stored.

So the debug adapter got the same request twice or more, and DAPSameNameSourceReferencesSessionTest failed intermittently on a slow runner ([5, 5, 9]).

Change

  • DAPClient.loadSource(sourceReference, store) sends source once for the loads of a source reference which run at once. A load which starts before the one which asked has stored its answer gets that answer, and stores it itself, in its own file, as before.
  • The shared load ends once its answer is stored, or once the request or the store fails, before its future completes. The next load asks again, so another text still replaces the document's (fix: each DAP source given by reference opens in its own editor tab, with its own text, also when sources share a name #2204), and a failed or cancelled request leaves nothing behind.
  • The in-flight loads are kept per client (their session), not by the file, which outlives the session.
  • DAPSourceReferencePosition loads through it.
Before After
The session, the Frames view and the frames of a source each sent a source request when they asked at once One request; the others share its answer

Tests

  • New testFramesWhichAskForTheTextOfTheirSourceAtOnceAskTheDebugAdapterOnce: red without the fix (3 requests instead of 2), green with it.
  • New testALoadOfASourceAsksAgainOnceTheRequestForItsTextFailed: guards against a stale in-flight entry.
  • A throwaway probe that holds the DAP thread inside the top frame's lazy position reproduced the CI failure 5 of 5 times before the fix, and 0 of 5 after it.
  • Headless on 2025.3: DAPSameNameSourceReferencesSessionTest ×6 and com.redhat.devtools.lsp4ij.dap.* (594 tests) are green.

…he debug adapter for its text once

A source given by reference gets its text from the 'source' request, and
each load of the text sent its own. Two loads of one source reference
could run at once, and the debug adapter was asked twice or more:
- DAPStackFrame.getSourcePosition() creates its position lazily, without
  a lock. The debug session publishes a stop (isSuspended(), the top
  frame) before it asks for the top frame's position on the DAP event
  thread, so the EDT, as the Frames view or the user showing the frame,
  and other threads ask for the same frame's position at once. Each
  caller that finds no position yet starts a load.
- A frame loads its source's text unless its file holds it already, and
  the file holds it only once the first answer is stored. Two frames of
  one source, a later frame, Jump to Source or the Loaded Sources tab
  started a load of their own in the meantime.

DAPClient.loadSource(sourceReference, store) now sends the 'source'
request once for the loads of a source reference which run at once:
- A load which starts before the one which asked has stored its answer
  gets that answer, and stores it itself, as before: in the file of its
  source reference, which keeps the text unless it differs.
- The shared load ends once its answer is stored, or once the request or
  the store fails, before its future completes. A load after it asks
  again, so another text from the debug adapter still replaces the
  document's (redhat-developer#2204), and a failed or cancelled request leaves nothing
  behind.
- The in-flight loads are kept by the client, whose source references
  they are, not by the file, which outlives the session.
- DAPSourceReferencePosition loads through it.

Tests, in DAPSameNameSourceReferencesSessionTest:
- testFramesWhichAskForTheTextOfTheirSourceAtOnceAskTheDebugAdapterOnce:
  two frames of a source ask for its text while the debug adapter holds
  its answer. It is asked once; without the fix, twice.
- testALoadOfASourceAsksAgainOnceTheRequestForItsTextFailed: the load
  after a failed request asks the debug adapter again and gets the text.
- testAFrameWhichIsNotShownLoadsItsTextInItsOwnFile and
  testEachFrameShowsTheTextOfItsOwnSource no longer fail intermittently
  with a second request for the first source, as on a slow CI runner.

Fixes redhat-developer#2263
@lagergren lagergren added this to the 0.30.2 milestone Nov 25, 2026
@lagergren lagergren added the bug Something isn't working label Nov 25, 2026
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Improvements
    • Concurrent requests for the same source now share a single retrieval, reducing duplicate work while preserving each request’s result processing.
    • If a source retrieval fails, a later request can try again instead of being blocked by the earlier failure.
    • These changes apply to source loads initiated by simultaneous frame requests and other concurrent requests for the same source.

DAPClient now shares overlapping source requests for the same source reference. Source positions use this shared loading path. Tests cover concurrent loads and verify that a later load can retry after a request fails.

Changes: Shared DAP source loads

Layer / File(s) Summary
Track and share source requests
src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java
DAPClient.loadSource shares an in-flight request by source reference and applies each caller’s store function to the response. It removes the entry when the request and store chain complete or fail.
Use shared loads for source positions and validate behavior
src/main/java/com/redhat/devtools/lsp4ij/dap/client/files/DAPSourceReferencePosition.java, src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPSameNameSourceReferencesSessionTest.java
Source positions retrieve source text through DAPClient.loadSource. Tests verify that concurrent loads make one request and that a later load can retry after a request failure.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Sequence Diagram(s)

sequenceDiagram
  participant PositionA as Source position A
  participant PositionB as Source position B
  participant DAPClient
  participant DebugAdapter
  PositionA->>DAPClient: loadSource(source reference)
  DAPClient->>DebugAdapter: source request
  PositionB->>DAPClient: loadSource(same source reference)
  DAPClient-->>PositionB: Join in-flight response
  DebugAdapter-->>DAPClient: SourceResponse
  DAPClient->>PositionA: Apply store callback
  DAPClient->>PositionB: Apply store callback
Loading

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to b512d

This change prevents duplicate debug adapter requests for the same source reference when loads overlap. Later loads still ask again, so new text can replace the document. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: concurrent loads of a DAP source given by reference now send one source request to the debug adapter. It matches the changeset (DAPClient.loadSource sharing an in-fl…
Description check Passed The description states the problem (duplicate DAP source requests from concurrent loads), the change (DAPClient.loadSource sharing in-flight loads, DAPSourceReferencePosition using it), and the tests …
Linked Issues check Passed Directly linked issue #2263 requires that concurrent loads of one source reference send one DAP source request, and that a later load still asks again when the text is not yet stored. Evidence at th…
Out of Scope Changes check Passed The changed files named in the summary are DAPClient.java (new loadSource method and sourceLoads field), DAPSourceReferencePosition.java (routes its source load through loadSource and drops the now-un…
Full details: Title check

Explanation

The title names the main change: concurrent loads of a DAP source given by reference now send one source request to the debug adapter. It matches the changeset (DAPClient.loadSource sharing an in-flight request), so it reflects the primary change.

Full details: Description check

Explanation

The description states the problem (duplicate DAP source requests from concurrent loads), the change (DAPClient.loadSource sharing in-flight loads, DAPSourceReferencePosition using it), and the tests added. It matches the changeset closely.

Full details: Linked Issues check

Explanation

Directly linked issue #2263 requires that concurrent loads of one source reference send one DAP source request, and that a later load still asks again when the text is not yet stored. Evidence at the reviewed head: DAPClient declares sourceLoads, a ConcurrentHashMap of in-flight SourceResponse futures keyed by source reference, per client. The raw summary states that the new public DAPClient.loadSource(sourceReference, store) shares an in-flight request with concurrent loads, applies each caller's store to the shared answer, and removes the entry after the store completes or fails. DAPSourceReferencePosition.loadAndResolveLineAsync now calls loadSource instead of calling the source request directly. The new test testFramesWhichAskForTheTextOfTheirSourceAtOnceAskTheDebugAdapterOnce covers the reported race, and testALoadOfASourceAsksAgainOnceTheRequestForItsTextFailed covers failure cleanup. The PR description reports red-to-green results and a probe that reproduced the CI failure 5/5 before the fix and 0/5 after. Limit of this review: the repository diff tool was unavailable, so the body of loadSource was not read directly. The behavior rests on the summary, the field declaration, and the PR description. Other paths named in the issue (Jump to Source, Loaded Sources) were not verified to route through loadSource.

Full details: Out of Scope Changes check

Explanation

The changed files named in the summary are DAPClient.java (new loadSource method and sourceLoads field), DAPSourceReferencePosition.java (routes its source load through loadSource and drops the now-unused SourceArguments import), and DAPSameNameSourceReferencesSessionTest.java (new tests and EvalServer support for failing and holding source responses). All of these serve the objective of issue #2263. No unrelated change is evident. The diff tool was unavailable, so the full set of hunks was not verified directly; this conclusion rests on the summary and the PR description.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e425929e-bd2e-46bd-940b-9c77ec8e0b3c
Commits

Reviewing files that changed from the base of the PR and between 1c74814 and b512dfb.

Files selected for processing: 3

  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/DAPClient.java
  • src/main/java/com/redhat/devtools/lsp4ij/dap/client/files/DAPSourceReferencePosition.java
  • src/test/java/com/redhat/devtools/lsp4ij/dap/client/DAPSameNameSourceReferencesSessionTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.91304% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.86%. Comparing base (7b66f44) to head (b512dfb).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...m/redhat/devtools/lsp4ij/dap/client/DAPClient.java 71.42% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2264      +/-   ##
==========================================
+ Coverage   55.82%   55.86%   +0.03%     
==========================================
  Files         848      848              
  Lines       36265    36283      +18     
  Branches     7502     5686    -1816     
==========================================
+ Hits        20245    20269      +24     
+ Misses      13103    13096       -7     
- Partials     2917     2918       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren
lagergren merged commit a83b369 into redhat-developer:main Nov 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DAP: loads of a source given by reference which run at once each send a source request; flaky DAPSameNameSourceReferencesSessionTest

1 participant