开发者

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

My app makes an outbound connection to a server using a specific source port (in anticipation of firewall problems - a hardened system will p开发者_StackOverflowrobably 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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜