OpenSSL sockets spin indefinitely on timeout in handshake #549

robinmessage opened this Issue Feb 25, 2013 · 1 comment


None yet

2 participants


OpenSSL sockets spin in a variety of ways (generally in an epoll wrapper) if there is a timeout during the handshake (might be other causes too but that seemed to cause the problem reliably.)

The culprit seems to be line 416 of, which is the only place the reads the return value of flushData. flushData returns true if there is no data left in the buffer - however, in the default case of an empty buffer, as far as I can see, this is going to cause an infinite loop.

I patched this on our production system by reversing the return value from flushData - so it returns true if there is still data in the buffer. This completely fixed our problem.

I suggest just swapping the return values from flushData, but not sure if that fits the bigger picture correctly.

diff --git a/src/org/jruby/ext/openssl/ b/src/org/jruby/ext/openssl/
index b692528..579ee5c 100644
--- a/src/org/jruby/ext/openssl/
+++ b/src/org/jruby/ext/openssl/
@@ -448,9 +448,9 @@ public class SSLSocket extends RubyObject {
             throw ioe;
         if (netData.hasRemaining()) {
-            return false;
-        }  else {
             return true;
+        }  else {
+            return false;

JRuby Team member

I'm closing this one in favor of #554.

@BanzaiMan BanzaiMan closed this Mar 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment