views:

179

answers:

1

Hi all,

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

A: 

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

jbu