okhttp: Unexpected TLS version: NONE
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.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 31 (1 by maintainers)
Commits related to this issue
- Fix "Unexpected TLS version:NONE" On the Android platform, when the TLS handshake is interrupted, SSLSession.getProtocol() may return "NONE". https://github.com/square/okhttp/issues/3719 https://... — committed to guoxin-nj/okhttp by guoxin-nj 6 years ago
- Fix "Unexpected TLS version:NONE" On the Android platform, when the TLS handshake is interrupted, SSLSession.getProtocol() may return "NONE". https://github.com/square/okhttp/issues/3719 https://githu... — committed to guoxin-nj/okhttp by deleted user 6 years ago
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.