java: bind exception address in use error when it isn't in use (as shown by netstat)

。_饼干妹妹 提交于 2019-12-23 22:27:48

问题


My app makes an outbound connection to a server using a specific source port (in anticipation of firewall problems - a hardened system will probably require ports to be specified ahead of time).

My problem is that my app makes the connection initially. However, if the connection ever breaks it will try again but the socket will get a BindException saying "address in use". This is not the case, as shown by netstat -pant. It shows that the the source port / remote socket pair does not exist (i.e., I'm not even seeing it in a WAIT mode, the connection just doesn't exist). I will try to connect forever without any success. I would think if it were a problem with the previous connection lingering, it would eventually timeout, but it doesn't. I get the bind exception forever.

In my case, I was connecting to 10.0.1.229:4001 FROM 10.0.1.20:4002. So I was using netstat to look for the source socket (10.0.1.20:4002) or the remote socket (10.0.1.229:4001), but neither was found after the initial connection was broken, indicating that the address should NOT be in use.

Is there something that would cause this connection to remain around even though netstat doesn't report it?

Please note I'm on linux and also I realize that using a random source port would work around my issue, but not fix it.

Please let me know.

Thanks, jbu


回答1:


close() was not being called when certain bad things happened - doh!



来源:https://stackoverflow.com/questions/1541151/java-bind-exception-address-in-use-error-when-it-isnt-in-use-as-shown-by-nets

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