More eyes on this one (rather than
JRUBY-6607) so I'm commenting here on the evenings explorations.
JRuby 1.6 or 1.7 both appear to drop the connection just fine with no lingering TIME_WAIT state when running on Java 7. I'm starting to think there's some JVM bug or improvement at play.
TIME_WAIT is the state that a socket goes into when closed if there's a possibility of packets still on the wire. It holds the socket in place to handle those rogue packets if they show up, and prevents additional connections that might be confused by those roque packets.
The length of time a socket will be in TIME_WAIT is determined at the kernel or system-global level.
I have read through MRI code again, and can't find anything they're doing to allow incomplete connections to disappear completely without TIME_WAIT. Evidence seems to be leading me to the conclusion that something OpenJDK/Sun JDK/Oracle JDK versions 1.6.x and lower are doing is causing these connections to hang around for a while.
FWIW, I see the following line in rbx for the script from
JRUBY-6607, which is also very confusing:
vm 69644 headius 5u IPv4 0xffffff8018dfb5e8 0t0 TCP 192.168.0.8:60211->10.255.255.1:http (SYN_SENT)
I'm not sure how to proceed with either this one or
JRUBY-6607 at this point. I have tried various combinations of socket flags, and nothing appears to change behavior. I've added additional layers of closing and finishing in RubyTCPSocket.initialize, and not had any luck. The only thing that works for me seems to be using Java 7.
Can anyone else confirm this bug or
JRUBY-6607 work as expected for them on Java 7 builds?