question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected TLS version: NONE

See original GitHub issue

These days so many crashes happened in our app. About 200+ Android devices has happened. And it’s always happend on Andorid 8.1.0. The OkHttp’s version I used is 3.10.0.

This is the crash’s stack information

0 java.lang.IllegalArgumentException: Unexpected TLS version: NONE
1 okhttp3.TlsVersion.forJavaName(TlsVersion.java:46)
2 okhttp3.Handshake.get(Handshake.java:55)
3 okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:242)
4 okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:198)
5 okhttp3.internal.connection.RealConnection.buildConnection(RealConnection.java:174)
6 okhttp3.internal.connection.RealConnection.connect(RealConnection.java:114)
7 okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:193)
8 okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:129)
9 okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:98)
10 okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
11 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
12 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
13 okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
14 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
15 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
16 okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
17 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
18 okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
19 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
20 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
21 com.weidian.lib.imagehunter.glidehunter.okhttp3.OkHttpUrlLoader$Factory$1.intercept(OkHttpUrlLoader.java:63)
22 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
23 okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
24 okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
25 okhttp3.RealCall.access$100(RealCall.java:33)
26 okhttp3.RealCall$AsyncCall.execute(RealCall.java:120)
27 okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
28 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
29 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
30 java.lang.Thread.run(Thread.java:764)

I found that OkHttp will not callback when java.lang.IllegalArgumentException happend. This exception is thrown by TlsVersion.forJavaName method

public static TlsVersion forJavaName(String javaName) {
  switch (javaName) {
    case "TLSv1.3":
      return TLS_1_3;
    case "TLSv1.2":
      return TLS_1_2;
    case "TLSv1.1":
      return TLS_1_1;
    case "TLSv1":
      return TLS_1_0;
    case "SSLv3":
      return SSL_3_0;
  }
  throw new IllegalArgumentException("Unexpected TLS version: " + javaName);
}

When invoke call’s enqueue method to get result async, if this exception happened, it will not callback onFailure method. And also I can’t catch it.

client.newCall(request).enqueue(new Callback() {
    @Override
    public void onFailure(Call call, IOException e) {

    }

    @Override
    public void onResponse(Call call, Response response) throws IOException {

    }
});
final class AsyncCall extends NamedRunnable {
  private final Callback responseCallback;

  @Override protected void execute() {
    boolean signalledCallback = false;
    try {
      Response response = getResponseWithInterceptorChain();
      if (retryAndFollowUpInterceptor.isCanceled()) {
        signalledCallback = true;
        responseCallback.onFailure(RealCall.this, new IOException("Canceled"));
      } else {
        signalledCallback = true;
        responseCallback.onResponse(RealCall.this, response);
      }
    } catch (IOException e) {
      //only IOException will catch and callback onFailure method
      if (signalledCallback) {
        // Do not signal the callback twice!
        Platform.get().log(INFO, "Callback failure for " + toLoggableString(), e);
      } else {
        responseCallback.onFailure(RealCall.this, e);
      }
    } finally {
      client.dispatcher().finished(this);
    }
  }
}

Is there any solution? Thank you.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:31 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
lizhangqucommented, Jun 12, 2018

I fix this problem by modifing async call to sync call and try catch it. The versions I used are 3.4.1, 3.9.1 and 3.10.0. All these versions have happened this problem. But it seems that 3.2.0 is ok. I am sorry that I have not focus on the crash number with different okhttp version.

0reactions
swankjessecommented, Jul 5, 2018

I’m getting ready to cut 3.11.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Crash: Unexpected TLS version: NONE #3719 - square/okhttp
Fatal Exception: java.lang.IllegalArgumentException: Unexpected TLS version: NONE at okhttp3.TlsVersion.forJavaName(TlsVersion.java:53) at ...
Read more >
Common issues when enabling TLS 1.2 - Microsoft Learn
This article provides advice for common issues that occur when you enable TLS 1.2 support in Configuration Manager.
Read more >
Validity90/Lobby - Gitter
I'm trying to get my 0097 running under Ubuntu 20.04 but I keep getting "Unexpected TLS version 4 0" when I run validity-sensors-tools...
Read more >
How to Fix the SSL/TLS Handshake Failed Error? - AboutSSL
Find out what's the SSL/TLS Handshake Failed Error, what causes this issue, and how you can solve it.
Read more >
Rehash: How to Fix the SSL/TLS Handshake Failed Error
This used to be a problem with WWW and non-WWW versions of websites. However, this issue has largely been mitigated by the certificate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found