IPV6 ServerSocket is still listening even after application crash

北城以北 提交于 2019-12-11 06:58:30

问题


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:


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.



来源:https://stackoverflow.com/questions/26888395/ipv6-serversocket-is-still-listening-even-after-application-crash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!