NetBeans and Tomcat – Transport Error 202

I generally develop any Java applications I’m working on in NetBeans and while I prefer to use GlassFish as a container I find myself using Tomcat quite a bit. Unfortunately the debugging connection between NetBeans and Tomcat can sometimes be less than perfect.

In this particular case I was receiving the following error message when I started Tomcat in debugging mode:

ERROR: transport error 202: failed to accept shared memory connection: stream closed
JDWP exit error JVMTI_ERROR_NONE(0): could not connect, timeout or fatal error [transport.c:326]

This was happening when I was starting an application that had an unusually large memory footprint of around 10GB although I don’t know if that was the underlying cause. What I do know is that it only happens when NetBeans is set to use shared memory for debugging.

The solution therefore is to switch from using shared memory to the other available option which is socket port. To do this from within NetBeans select Tools > Servers. In the window that opens select the Tomcat server that you wish to modify. Select the Startup tab and then change the Debugger Transport from Shared Memory Name to Socket Port. You can set a specific port if you wan’t but it’s unlikely that the currently selected port is in use. When you are finished close the server settings window, kill the Tomcat process and then start it up again. You should now find that the debugger will run perfectly.

Personally I prefer the shared memory option as it seems to have a lower impact on performance which is important to me on my development machine. In production I almost always use the socket port option because the Tomcat process I’m debugging is generally on a different machine. The performance of socket port when the Tomcat process is on another machine is less than blistering but it does work and it’s a great solution if you really must examine a live process.