0

I configure launch.json to launch Java debugger and working successfully. After a short while, I see error ERROR: transport error 202: recv error: Connection reset by peer. I did google it, and it was suggested to change the debug argument from:

-agentlib:jdwp=transport=dt_socket,server=n,suspend=y,address=localhost:52252

to:

-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:52252

The debug arguments above are auto generated by vscode. How I can change it? I didn't find a way to configure such argument. The only option is to configure a task to run the command, and configure a debug option to run the task to launch the debugger and attached to that debugger session.

I am checking if there is a way to change the part to server=y as it is much easier.

tarekahf
  • 738
  • 1
  • 16
  • 42
  • Use the `vmArgs` parameter in *launch.json* to add arguments to the jvm. Or use `"java.debug.settings.vmArgs":` configuration in *settings.json*. Here is the [official documentation](https://code.visualstudio.com/docs/java/java-debugging#_launch) explaining it. – JialeDu Nov 25 '22 at 08:20
  • Is there any progress on the problem? If you find the solution, you could click '✔' to mark it as an answer to change its status to Answered. It will also help others to solve a similar issue. See also [stackoverflow.com/help/why-vote](https://stackoverflow.com/help/why-vote) – JialeDu Dec 01 '22 at 05:50
  • I accepted the answer but it requires modification. Check the latest comments I added. I can't modify the answer due to limits reached by the site. Can you help? – tarekahf Dec 02 '22 at 21:27

1 Answers1

1

Stack Overflow seems to have these answers. I never tested them myself though.

If it helps, one of the SO questions, and a comment here, has a link to the VSCode configuration reference, https://code.visualstudio.com/docs/java/java-debugging#_attach . There you can see the attach request options.

My understanding of the attach vs launch is that

  • launch runs your App, and then automatically attaches a debugger to it.
  • attach is used only in cases where you have an already running JVM, lets say on some remote server, and you want to debug it.

How are you running starting your JVM? My guess would be that if you are starting the JVM from terminal, then put the server=y option there. If you want the VSCode to run the JVM, which I assume is the case, then the launch request is what you want.

vladimirror
  • 729
  • 12
  • 8
  • Thanks a lot. I though if I change `server=n` to `server=y` that would solve the error `ERROR: transport error 202: recv error: Connection reset by peer`. I managed to create an attach request with `server=y` but the error would be thrown after a couple of minutes even after debugging is active as successful. Can you help find out why this error is thrown during the debugging session? – tarekahf Nov 28 '22 at 15:05
  • @tarekahf oof, I am like happy to help, but we would need to find a better chat option :D Does it work the first couple of minutes though? Also, I am no Java expert so I am not sure I will be of huge help, just saying. – vladimirror Nov 28 '22 at 16:22
  • That's awesome! I am searching now and I have doubt that it's the application causing this error. I will find a multi-module sample maven simple project and try to debug and see if I will get this error. – tarekahf Nov 28 '22 at 16:43
  • I marked this as an answer, but I will edit it later to add more details. Basically, it is only possible to change debug arguments with the `attach request`. – tarekahf Dec 01 '22 at 18:34
  • @tarekahf Really? AFAIK according to the docs, the `attach` config has only "location" options ie. where to connect, and everything else seems to be done using the `launch` config. Although I might be just misunderstanding your question. – vladimirror Dec 02 '22 at 16:11
  • Yes, the attach request depends on a task to be launched before the attach. The task will invoke the command line to launch Java.exe with the custom debug arguments. You can rip off the java.exe command from the launch request shown the integrated terminal and create the shell task accordingly. I think one of the docs you mentioned explained this in details. I can't edit the answer due to some limitation now with the site. – tarekahf Dec 02 '22 at 20:12
  • This is the article with a lot of details to configure a `launch request` with a `preLaunchTask` task configuration: https://github.com/microsoft/vscode-java-debug/blob/main/Configuration.md#attach-to-a-debuggee. If you can edit the answer and provide such details, that would be great. – tarekahf Dec 02 '22 at 21:25
  • @tarekahf thank you! I had no idea about that repository. I have added it into the text. – vladimirror Dec 05 '22 at 15:02