Lingering tcp connection in LISTEN state
- by Silvio Donnini
My java application can sometimes be killed by an external script. This can be done either with SIGTERM or with SIGKILL.
The application is a server which receives many connections per second, and it can be killed while trying to serve them.
I would like to restart the application whenever it's killed, so I have prepared a script for that purpose.
The problem is that, once the app has been killed, the new application instance can't bind to the port used by the previous instance, because the "Address is already in use". The previous instance's process has been definitely terminated, anyway the offending listening port is still there, but it is assigned to bash (or sh on other machines).
Obviouly, my goal is to restart the application and let it bind successfully to the previous address.
I've tried waiting more than 200 seconds before restarting to no avail, anyway I can't afford to wait that much.
I've encountered this problem on all the machines I've ran the application (which is a jetty server with java 1.6).
Any suggestion is appreciated,
thanks,
Silvio