sbrisson
sbrisson

Reputation: 346

Address already in use: JVM_Bind but no process is listed using port with netstat

I have a java process that make use of ServerSocket API (Java 8) and bind to the local port 12000. Process runs under a Windows service Wrapper (exe4j). I have a scheduled task that runs at 4am that stop the service and restart it after a couple of seconds. That process is installed over 400 customers locations.

Everything was running smooth until about last friday. A few processes failed to restart properly at 4am. On 2 servers I was able to connect and verify, the restart failed with both a "Address already in use: JVM_Bind". It's seems that the port 12000 was still in use by a the system.

I used every tools (processexplorer, tcpview, netstat -ano, name it) I know to try to find the process... with no success. Only a machine reboot fixed the issue. But problem came back a night or two later.

After some reading, I saw that I was doing a sockect.accept() with infinite timeout so I changed it for socket.setSoTimeout(15000); socket.accept(); instead.

I putted the new version in place but the problem is still there.

Machines got Windows updates. I did tests with the same Windows version fully updated but I can't reproduce.

I'm out of solution now.

Any ideas Thanks

Upvotes: 3

Views: 2041

Answers (3)

Hackerman
Hackerman

Reputation: 101

I just ran into a similar scenario. I am building a java webserver, it uses mysql-j-connector for sql.

My goal was to upgrade the server, so first I shut it down via the administrative client. I compiled and tried to run the new version but it returned an error saying the address was already in use. I tried using multiple tools (with and without root access) to try to shut down the process using the target port, but nothing worked.

What I did to fix it was to use Htop

htop

turns out the mysql-j-connectior was still running, am not sure why. I killed that process (which as mentioned before did not register as using the desired port number) and after that I was able to run the server.

Upvotes: 1

sbrisson
sbrisson

Reputation: 346

A windows update affected the release of address/port after process shutdown.

Refer to Address Bind exception in Tomcat for solution.

Upvotes: 2

JoSeMa
JoSeMa

Reputation: 151

I am on the same problem here. I've got several Java instances running as servers but as soon as any of those Java applications is killed and restarted then they fail to do so complaining that the port is still in use. Never happened before and I used to restart them every now and then.

My Windows server machine also received some new updates a few days ago.

By the way, I am using a tool to monitor ports and applications and those ports are not being used by any program, so the application is actually killed.

Upvotes: 1

Related Questions