Skip to content

fix(java): bind the launched JVM's debug port to loopback - #1387

Merged
debugmcpdev merged 3 commits into
mainfrom
fix/java-jdwp-loopback
Nov 29, 2026
Merged

debugmcpdev merged 3 commits into
mainfrom
fix/java-jdwp-loopback

Conversation

@debugmcpdev

@debugmcpdev debugmcpdev commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

What changes

In launch mode the JDI bridge started the JVM with -agentlib:jdwp=...,address=*:<port>, which listens on every network interface, and then attached through localhost. JDWP has no authentication, so that port should never be reachable from another machine.

  • The JVM is started with address=127.0.0.1:<port>.
  • The bridge attaches to the same literal address.
  • The bridge's free-port probe binds loopback as well, so nothing the bridge opens listens beyond loopback.

Attach mode is unchanged: it connects to the host and port it is given.

The wildcard dates from the adapter's first commit. Neither its message nor the code gives a reason for it, and nothing in the repository relies on reaching the launch's port from another machine: the Dockerfile exposes other ports, and the remote recipes start their own JVMs for attach.

Test

tests/adapters/java/integration/java-launch-loopback.test.ts launches through the bridge and compares the JDWP address of the real launch command with the port the JVM announces. On the previous bridge it fails with Expected: "127.0.0.1:<port>", Received: "*:<port>". It starts the bridge the way it ships, and it does not depend on the JVM's banner being the first line the program prints.

Verified

  • The new test fails before the change and passes after it, three times on Windows and three times on Linux, and once with JAVA_TOOL_OPTIONS set (an extra banner line).
  • Java adapter unit tests: 202 passed on both machines.
  • The eight Java end-to-end suites at 0ed0ce07: 22 of 22 on Windows and on Linux. The commits after it change the test and the changelog entry's name only.
  • Independent review (Claude Opus, read-only, with a sweep of every other listener in the product): nothing above minor in this change. Its minor findings were all in the test and are fixed in the last commit. What the sweep found elsewhere is filed separately.

Who wrote what

The two substitutions, the test and the docs sentence were written by a GPT worker. The manager session (Claude) changed the port probe, verified the failing-first runs, and wrote the changelog entry and this description.

🤖 Generated with Claude Code

https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs

cynarlab and others added 2 commits November 29, 2026 16:08
In launch mode the JDI bridge started the JVM with
-agentlib:jdwp=...,address=*:<port>, which listens on every network
interface, and attached through "localhost" after a short wait. The
JVM is now started with address=127.0.0.1:<port> and the bridge
attaches to the same literal address. The bridge's free-port probe
binds loopback as well, so nothing the bridge opens listens beyond
loopback. Attach mode is unchanged.

The wildcard dates from the adapter's first commit (abd5dfe). Neither
its message nor the code gives a reason for it, and nothing in the
repository relies on reaching the launch's port from another machine.

Test: an integration case launches through the bridge and compares the
JDWP address of the real launch command with the port the JVM
announces. It fails on the previous bridge with "*:<port>".

The two substitutions, the test and the docs sentence were written by
a GPT worker. The manager session changed the port probe, verified the
failing-first run and wrote the changelog entry.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
The fragment was written under a guessed number that an unrelated
issue took in the meantime. No source changes.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
@codecov

codecov Bot commented Nov 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Review findings on the test of the previous commits; no source change.

- It took the first output frame for the JVM's JDWP banner, so any
  line printed ahead of it (for example "Picked up JAVA_TOOL_OPTIONS")
  failed the test. It now waits for the frame that matches.
- It started the bridge with -Djava.net.preferIPv4Stack=true, which
  production does not pass. The flag is gone and the bridge is started
  with --owner-pid, as it ships.
- The bridge's start is retried when its reserved port is lost, its
  pipes are drained for its whole life, a client that never connected
  is not asked to disconnect, and the work directory is removed with
  retries.

Found by a Claude (Opus) review and a Gemini review of the sibling
test; written by the GPT worker that wrote the test; verified by the
manager session: it still fails on main's bridge with "*:<port>".

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
@debugmcpdev
debugmcpdev marked this pull request as ready for review November 29, 2026 22:14
@debugmcpdev
debugmcpdev merged commit e432154 into main Nov 29, 2026
18 checks passed
@debugmcpdev
debugmcpdev deleted the fix/java-jdwp-loopback branch November 29, 2026 22:14
debugmcpdev pushed a commit that referenced this pull request Nov 29, 2026
Brings in the two Java bridge fixes (#1387, #1393). No conflicts; no
file of this change is touched by them.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015BDrn82vMcRzWFDD9aUbZs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants