lantern icon indicating copy to clipboard operation
lantern copied to clipboard

When running on OS X 10.8 with Java 7 build 25, SSL handshaking occasionally fails with a SocketException: invalid_argument

Open oxtoacart opened this issue 13 years ago • 13 comments

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.

oxtoacart avatar Sep 09 '13 13:09 oxtoacart

Note - this applies to other types of blocking sockets that we open as well, for example the one used by ControlEndpointXmppP2PClient.

oxtoacart avatar Sep 09 '13 13:09 oxtoacart

This issue appears to be as of Java 7 Build 11.

oxtoacart avatar Sep 09 '13 13:09 oxtoacart

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.

oxtoacart avatar Sep 09 '13 14:09 oxtoacart

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.

myleshorton avatar Sep 09 '13 18:09 myleshorton

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.

oxtoacart avatar Sep 09 '13 19:09 oxtoacart

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.

oxtoacart avatar Sep 09 '13 20:09 oxtoacart

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.

oxtoacart avatar Sep 09 '13 20:09 oxtoacart

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 .

myleshorton avatar Sep 09 '13 20:09 myleshorton

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.

oxtoacart avatar Sep 09 '13 20:09 oxtoacart

@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.

oxtoacart avatar Sep 12 '13 11:09 oxtoacart

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.

oxtoacart avatar Sep 25 '13 12:09 oxtoacart

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.

lanterndev avatar Jan 30 '14 18:01 lanterndev

(Should become obsolete when we switch to the Go version.)

scouttle avatar Sep 29 '14 17:09 scouttle