When running on OS X 10.8 with Java 7 build 25, SSL handshaking occasionally fails with a SocketException: invalid_argument
This happens because we often set a socket timeout when using HttpClient and that option is broken on OS X:
http://stackoverflow.com/questions/16191236/tomcat-startup-fails-due-to-java-net-socketexception-invalid-argument-on-mac-o
Per the above post, I've added a test called "SelectBrokenOnOSX" that reproduces the underlying issue.
Note - this applies to other types of blocking sockets that we open as well, for example the one used by ControlEndpointXmppP2PClient.
This issue appears to be as of Java 7 Build 11.
For now, I've disabled setting a socket timeout where I can (other than ControlEndpointXmppP2PClient, which is in LittleShoot.
Before closing this, I think I'll need to provide an alternative to setting a socket timeout since it wouldn't be acceptable to just let connections hang. The way that Netty does this in an NIO world is using a watchdog thread.
I don't understand the relationship between the test and SO_TIMEOUT. The test doesn't hit SO_TIMEOUT in any way right? That seems like an unbelievably huge bug to me.
Yeah, it's a biggie. And oddly, the link from the StackOverflow post to the bug is dead, and searching the bug database doesn't bring anything up.
I first ran across this back when doing LittleProxy unit tests, where I solved it by taking out the SO_TIMEOUT setting from our HttpClients. I more recently ran across it while running the SslHttpProxyServerTest. It failed intermittently during SSL handshaking. Turning on SSL tracing revealed an underlying SocketException: Invalid argument.
I also don't understand the relationship between the test and setting the timeout on client sockets. I'll try running dtrace to what I can find.
I've updated the unit test to show the same behavior due to setting a socket timeout on a client socket.
Looking at the Java source code, the problem happens anytime that the native method NET_Timeout is called. Oddly, the socketAccept method of PlainSocketImpl.c calls NET_Timeout no matter what your timeout is. The other place where NET_Timeout gets called is in SocketInputSream.c. Here, it only gets called if the timeout is non-zero. This is the path that I think is breaking with HttpClient, which is why the workaround of leaving the timeout at its default of zero works.
I've filed a bug with Oracle about this. Apparently they moderate their bug reports, so I don't have an actual bug number yet. I'll post it once I have it.
God this is so crazy -- thanks for all the digging. I'm shocked a bug that big made it into production.
On Mon, Sep 9, 2013 at 1:25 PM, oxtoacart [email protected] wrote:
I've filed a bug with Oracle about this. Apparently they moderate their bug reports, so I don't have an actual bug number yet. I'll post it once I have it.
— Reply to this email directly or view it on GitHubhttps://github.com/getlantern/lantern/issues/942#issuecomment-24111581 .
Pretty wild, right? The NIO stuff doesn't seem to suffer from the same problem, so perhaps we should just switch to using a Netty-based HTTP client like this.
@myleshorton and I recently did some work to reduce resource utilization on the new version of LittleProxy (fewer threads, fewer resources descriptors, idling out all connections including tunneled ones). I've run quite a bit on the new version and have let it run overnight, and it has not crashed.
I still feel that the SWT is a bit of a liability, so I'm going to leave this open for now, but it's not high priority.
Okay, the JRE OSX issue looks like it's fixed in release 7u60:
https://bugs.openjdk.java.net/browse/JDK-8023403
I can't find an estimated date for that release, but there you have it.
Still no release date set for 7u60 on the versions page, though 7u65 (the next highest Java 7 release listed) is set for 2014-07-14. Java 8 is due out on 2014-03-17 though.
(Should become obsolete when we switch to the Go version.)