title: OKhttp : SSLProtocolException: SSL handshake terminated
body: <p>I'm trying to figure out why sometimes I get this error</p>
  
  <blockquote>
    <p>javax.net.ssl.SSLProtocolException: SSL handshake terminated:
    ssl=0x60d46c90: Failure in SSL library, usually a protocol error
    error:1409443E:SSL routines:SSL3_READ_BYTES:tlsv1 alert inappropriate
    fallback (external/openssl/ssl/s3_pkt.c:1256 0x60d57f40:0x00000003)</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/QWTXA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QWTXA.png" alt="enter image description here"></a></p>
  
  <p><strong>the code that makes this request:</strong></p>
  
  <pre><code>private &lt;T&gt; void send(final String url, final Map&lt;String, String&gt; args, 
      final RequestCallback&lt;T&gt; callback, final Parser&lt;T&gt; pParser, 
      final Context pContext, final HTTP_METHOD method, 
      final Map&lt;String, String&gt; headers, final BODY_TYPE bodyType) {
  
      final Request.Builder builder = getBuilder(url);
      populateHeaders(builder, headers);
      final RequestBody body = getBody(args, bodyType);
  
      if(method==HTTP_METHOD.POST) {
          builder.post(body);
      } else if(method==HTTP_METHOD.GET) {
          builder.get();
      } else if(method==HTTP_METHOD.PUT) {
          builder.put(body);
      } else if(method==HTTP_METHOD.PATCH) {
          builder.patch(body);
      } else {
          throw new RuntimeException("Please specify correct method name!");
      }
  
      Request request = builder.build();
      debugRequest(request, whoCalledThisMethod());
      call = client.newCall(request);
      call.enqueue(new StandardRequestCallback(pContext, callback, pParser));
  }
  </code></pre>
  
  <p>I've found that if my app gets this exception, force-closing it, followed by re-launching it, can successfully complete the request... however, a short while later, it fails again with this SSL Exception.</p>
  
  <p>What could be wrong ?</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I made a very small test app that uses code from the okHttp recipes page <a href="https://github.com/square/okhttp/wiki/Recipes" rel="nofollow noreferrer">https://github.com/square/okhttp/wiki/Recipes</a> and I've repro'd the SSL Handshake Exception !!</p>
  
  <pre><code>06-27 13:59:08.068 30006-32692/a.b.ssltestapp W/System.err: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0x60068d10: Failure in SSL library, usually a protocol error
  06-27 13:59:08.068 30006-32692/a.b.ssltestapp W/System.err: error:1409443E:SSL routines:SSL3_READ_BYTES:tlsv1 alert inappropriate fallback (external/openssl/ssl/s3_pkt.c:1256 0x6006e6b0:0x00000003)
  06-27 13:59:08.078 30006-32692/a.b.ssltestapp W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:568)
  06-27 13:59:08.078 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.internal.io.RealConnection.connectTls(RealConnection.java:188)
  06-27 13:59:08.078 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.internal.io.RealConnection.connectSocket(RealConnection.java:145)
  06-27 13:59:08.078 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.internal.io.RealConnection.connect(RealConnection.java:108)
  06-27 13:59:08.078 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:188)
  06-27 13:59:08.088 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:127)
  06-27 13:59:08.088 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:97)
  06-27 13:59:08.088 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:289)
  06-27 13:59:08.088 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:241)
  06-27 13:59:08.088 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.RealCall.getResponse(RealCall.java:240)
  06-27 13:59:08.088 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
  06-27 13:59:08.088 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
  06-27 13:59:08.098 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.RealCall.access$100(RealCall.java:30)
  06-27 13:59:08.098 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
  06-27 13:59:08.098 30006-32692/a.b.ssltestapp W/System.err:     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:33)
  06-27 13:59:08.098 30006-32692/a.b.ssltestapp W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  06-27 13:59:08.098 30006-32692/a.b.ssltestapp W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  06-27 13:59:08.098 30006-32692/a.b.ssltestapp W/System.err:     at java.lang.Thread.run(Thread.java:841)
  06-27 13:59:08.098 30006-32692/a.b.ssltestapp W/System.err:     Suppressed: javax.net.ssl.SSLHandshakeException: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0x60068d10: Failure in SSL library, usually a protocol error
  06-27 13:59:08.098 30006-32692/a.b.ssltestapp W/System.err: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure (external/openssl/ssl/s3_pkt.c:1256 0x5ff9aa20:0x00000003)
  06-27 13:59:08.108 30006-32692/a.b.ssltestapp W/System.err:         ... 18 more
  06-27 13:59:08.108 30006-32692/a.b.ssltestapp W/System.err:     Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0x60068d10: Failure in SSL library, usually a protocol error
  06-27 13:59:08.108 30006-32692/a.b.ssltestapp W/System.err: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure (external/openssl/ssl/s3_pkt.c:1256 0x5ff9aa20:0x00000003)
  06-27 13:59:08.118 30006-32692/a.b.ssltestapp W/System.err:     at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
  06-27 13:59:08.118 30006-32692/a.b.ssltestapp W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:486)
  06-27 13:59:08.118 30006-32692/a.b.ssltestapp W/System.err:         ... 17 more
  06-27 13:59:08.118 30006-32692/a.b.ssltestapp W/System.err: Caused by: javax.net.ssl.SSLProtocolException: SSL handshake terminated: ssl=0x60068d10: Failure in SSL library, usually a protocol error
  06-27 13:59:08.118 30006-32692/a.b.ssltestapp W/System.err: error:1409443E:SSL routines:SSL3_READ_BYTES:tlsv1 alert inappropriate fallback (external/openssl/ssl/s3_pkt.c:1256 0x6006e6b0:0x00000003)
  06-27 13:59:08.118 30006-32692/a.b.ssltestapp W/System.err:     at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
  06-27 13:59:08.118 30006-32692/a.b.ssltestapp W/System.err:     at com.android.org.conscrypt.OpenSSLSocketImpl.startHandshake(OpenSSLSocketImpl.java:486)
  06-27 13:59:08.118 30006-32692/a.b.ssltestapp W/System.err:     ... 17 more
  </code></pre>