IPV6 ServerSocket is still listening even after application crash

295 views Asked by At

I created a ServerSocket using:

InetSocketAddress inetsktaddr = new InetSocketAddress(0);
ServerSocket sckt = new ServerSocket();
sckt.bind(inetsktaddr);
Socket socket = sckt.accept();

when the application is running, using netstat i found,

TCP    0.0.0.0:49906          0.0.0.0:0              LISTENING       9196
TCP    [::]:49906             [::]:0                 LISTENING       9196

SOMETIMES WHEN THE APPLICATION CRASHES, netstat result says:

TCP    [::]:49906             [::]:0                 LISTENING       9196

when searched for the process id 9196, no such process exists. It was the java.exe process id when the application was running. What is the reason for this to happen?

I am using java 1.5 and Windows 7 Professional

EDIT

After sometime i found the following: my application starts mysql database. Sometimes when java.exe crashes, mysql will not crash. The db server will be up only. When this issue came (:: alone in listening state), i killed mysql process, immediately that :: socket stopped listening. So mysql is somehow preventing the :: to go away when java crashes. Not able to find reason for it.

1

There are 1 answers

0
Praveen Kumar On BEST ANSWER

Atlast i found the reason, its a JVM Bug. (http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6598160)

Child processes will inherit ONLY IPV6 SOCKET HANDLES AND NOT IPV4 SOCKET HANDLES. Hence the issue came to me.

Fix is i should either upgrade JVM or listen only in ipv4 server socket.