On 2 February 2011 22:59, Brian Hurt <[email protected]> wrote: > > > On Wed, Feb 2, 2011 at 5:51 PM, John Cowan <[email protected]> wrote: >> >> On Wed, Feb 2, 2011 at 5:47 PM, Robert Fischer <[email protected]> >> wrote: >> >> > Wait—let me get this straight. Even if you close a socket, you've >> > still consumed a port number, and there's no way to free the port >> > numbers for re-use? >> >> No, not at all. If the socket has been closed long enough, the kernel >> will free the port number, and it can be reallocated. I was simply >> speculating that the OP was opening ports faster than he was closing >> them, but apparently not. > > I'm looking into this. It's possible, even probable, that my "rate of > socket opening" does increase shortly before I hit the problem. It's not > wrapping the port numbers that are the problem, it's wrapping them too fast. > > This is especially relevant because it looks like the problem goes away > after a second or two. So this is making sense. Thanks.
This does sound like a TIME_WAIT problem. The socket is supposed to be held in this state (and is unavailable for reuse) for twice the transit time of a packet across the network. In practice most implementations use a fixed period of time (around 5 seconds). So if you manage to open and close 30K sockets in the TIME_WAIT period then you'll run out of sockets even if you have none open. Most TCP/IP implementations have a way of tuning the TIME_WAIT period. Using setReuseAddress(true) should work too. John Wilson -- You received this message because you are subscribed to the Google Groups "JVM Languages" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/jvm-languages?hl=en.
