Video in progress

Why is leaving remote debugging (JDWP) attached to a prod JVM dangerous, and what do you do instead?

Anyone who connects to the JDWP port can execute any code, which is full remote control. A breakpoint also freezes a thread and holds up real requests. On prod I use logs, JFR, thread dumps and, if needed, read-only observation tools.

📖 Answer

Remote debugging is turned on like this:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005

The problems:

Security. JDWP has no authentication. Someone who connects to the port can call any method through the debugger, for example Runtime.exec. There are bots that scan the internet for open 5005 ports. Since JDK 9, address=5005 listens only on localhost, while *:5005 listens to everyone. Most people don't know this difference.

Reliability. A thread stopped at a breakpoint holds up the request and doesn't release its locks. A breakpoint that stops the whole JVM (suspend all) kills the service: timeouts, retries, failing health checks.

Performance. Merely having the agent loaded is almost free, but when you set a breakpoint or watchpoint, the affected code may get deoptimized.

Instead:

  • reasonably detailed logs and an adjustable log level (Spring Boot actuator /loggers);
  • jcmd Thread.print, a JFR recording, jcmd VM.log;
  • reproducing on staging with a copy of the prod traffic;
  • if you really need it: take one pod out of rotation, open the port only through kubectl port-forward, and delete the pod after the work.

If JDWP is always on in a prod image, I treat it as a security incident.