Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash: Unexpected TLS version: NONE #3719

Closed
anthony3444 opened this issue Dec 12, 2017 · 24 comments
Closed

Crash: Unexpected TLS version: NONE #3719

anthony3444 opened this issue Dec 12, 2017 · 24 comments
Labels
bug Bug in existing code
Milestone

Comments

@anthony3444
Copy link

Hi there!

First at all thank you very much for your library!

I've integrated okhttp3 since couple months ago; there were no problem until yesterday with an user (Huawei, model MHA-L29, on Android 7.0):

Fatal Exception: java.lang.IllegalArgumentException: Unexpected TLS version: NONE
       at okhttp3.TlsVersion.forJavaName(TlsVersion.java:53)
       at okhttp3.Handshake.get(Handshake.java:56)
       at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:300)
       at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:268)
       at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:160)
       at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:256)
       at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:134)
       at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:113)
       at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
       at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
       at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
       at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
       at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
       at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:776)

Have you got some ideas about this crash?

Thank you very much guys!

@yschimke
Copy link
Collaborator

yschimke commented Dec 12, 2017

Does your app change the SSL provider in any way? to GMS services e.g. include ProviderInstaller.installIfNeeded. It could also just be the setup of that phone.

Is it a one-off or consistently reproducible?

I've seen a similar issue in rare timing cases either before or after a network issue, a non-standard SSL provider can return NONE as the string. OkHttp might have to handle this more gracefully.

https://github.com/google/conscrypt/blob/c88f9f55a523f128f0e4dace76a34724bfa1e88c/common/src/main/java/org/conscrypt/SSLNullSession.java#L149-L151

@anthony3444
Copy link
Author

Hi!

About your questions:

  • "Does your app change the SSL provider in any way? to GMS services e.g. include ProviderInstaller.installIfNeeded" : no change
  • "Is it a one-off or consistently reproducible?" : just only 1 crash until now

Is there a manner to catch this exception in my App to avoid a crash?

@asfdfdfd
Copy link

asfdfdfd commented Dec 13, 2017

I could confirm this issue on multiple devices. You could look in details at Crashlytics http://crashes.to/s/188322d298a

Here is part of my application from stacktrace https://gist.github.com/anonymous/eb4c8d96de290e84c3e5be093060023f

I use GMS ProviderInstaller and custom SSLSocketFactory.

@dgadelha
Copy link

+1:

image

@yschimke
Copy link
Collaborator

n.b. my PR fix will turn these into IOExceptions and handle them cleanly e.g. retry other connection routes. But it won't fix an underlying fatal problem e.g. connecting to specific servers with a custom SSLSocketFactory.

@yschimke yschimke added the bug Bug in existing code label Dec 28, 2017
@yschimke yschimke added this to the 3.10 milestone Dec 30, 2017
@anthony3444
Copy link
Author

@yschimke: this crash stills there :( I've added ProviderInstaller.installIfNeeded into my App + a custom SSLSocketFactory. It's really rare, but today 1 user had this crash (Android 7.0 on Galaxy S7 Edge).

@yschimke
Copy link
Collaborator

@anthony3444 the fix is in the next release (3.10), until then when they happen you will get a crash from OkHttp.

@hidroh
Copy link

hidroh commented Jan 22, 2018

We're observing the same crash. 100% of crashes happen to users on Google phones running Android 8.1.0, though we can't reproduce on the same device we have.

@sergicastellsague
Copy link

@yschimke do we have an ETA of this release?

@yschimke
Copy link
Collaborator

I don't, I think we had planned for a 3.10 earlier than this. cc @swankjesse @JakeWharton

@kelset
Copy link

kelset commented Jan 29, 2018

Hey guys, same crash - it's quite rare for us too, was just wondering if the issue could be kept open until 3.10 is released.

Are there any extra informations that I could provide that may be needed/helpful?

@yschimke yschimke reopened this Jan 30, 2018
@swankjesse
Copy link
Collaborator

I think this is fixed in 3.10.

@anna-b
Copy link

anna-b commented Feb 20, 2018

@swankjesse is 3.10 expected to be released any time soon? thanks!

@kelset
Copy link

kelset commented Feb 20, 2018

@anna-b if you look at the milestone they seem to be aiming for end Feb. So a bit more than a week.

guoxin-nj added a commit to guoxin-nj/okhttp that referenced this issue Jun 29, 2018
On the Android platform, when the TLS handshake is interrupted, SSLSession.getProtocol() may return "NONE".

square#3719
square#3973
guoxin-nj pushed a commit to guoxin-nj/okhttp that referenced this issue Jun 29, 2018
On the Android platform, when the TLS handshake is interrupted, SSLSession.getProtocol() may return "NONE".
square#3719
square#3973
@vasiledoe
Copy link

vasiledoe commented Jul 10, 2018

same error using 3.10 with Retrofit 2

Fatal Exception: java.lang.IllegalArgumentException: Unexpected TLS version: at okhttp3.TlsVersion.forJavaName(TlsVersion.java:53) at okhttp3.TlsVersion.forJavaNames(TlsVersion.java:59) at okhttp3.ConnectionSpec.tlsVersions(ConnectionSpec.java:113) at okhttp3.ConnectionSpec.toString(ConnectionSpec.java:221) at java.lang.String.valueOf(String.java:2683) at java.lang.StringBuilder.append(StringBuilder.java:129) at java.util.AbstractCollection.toString(AbstractCollection.java:458) at java.util.Collections$UnmodifiableCollection.toString(Collections.java:1108) at java.lang.String.valueOf(String.java:2683) at java.lang.StringBuilder.append(StringBuilder.java:129) at okhttp3.internal.connection.ConnectionSpecSelector.configureSecureSocket(ConnectionSpecSelector.java:70) at okhttp3.internal.connection.RealConnection.connectTls(RealConnection.java:274) at okhttp3.internal.connection.RealConnection.establishProtocol(RealConnection.java:251) at okhttp3.internal.connection.RealConnection.connect(RealConnection.java:151) at okhttp3.internal.connection.StreamAllocation.findConnection(StreamAllocation.java:192) at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(StreamAllocation.java:121) at okhttp3.internal.connection.StreamAllocation.newStream(StreamAllocation.java:100) at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:42) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:120) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at com.justdo.logic.network.RestClient$1.intercept(RestClient.java:60) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92) at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67) at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:185) at okhttp3.RealCall$AsyncCall.execute(RealCall.java:135) at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) at java.lang.Thread.run(Thread.java:762)

@yschimke
Copy link
Collaborator

Mostly fixed in 3.10, but there was a race condition. Hopefully fixed correctly in 3.11

@dave-r12
Copy link
Collaborator

Also, that stack trace appears to be 3.8.

@TomasYu
Copy link

TomasYu commented Jul 18, 2018

Is this fixed in 3.11?

@yschimke
Copy link
Collaborator

Yes, if you see it with 3.11 or it manifests in other similar ways, please open an issue.

@gongzelong0718
Copy link

@dave-r12 ve
How do you judge that the issue opened by @vasiledoe happened when using okhttp 3.8 or do I misunderstanding something?

@gongzelong0718
Copy link

@yschimke

Thanks for your reply.
Could you specify which commit in 3.11 fix that issue?

I just upgrade to 3.10 to fix another crash (#3438)
Could you explain more about under which rare condition does this crash still happen in 3.10 ?

@swankjesse
Copy link
Collaborator

@gongzelong0718 please give 3.11 a try. The commits in the release are on our git history.

@dave-r12
Copy link
Collaborator

dave-r12 commented Aug 1, 2018

@gongzelong0718 the stack trace includes class names and line numbers. We can correlate that information with git tags to understand possible versions. For example: okhttp3.ConnectionSpec.tlsVersions(ConnectionSpec.java:113) at

In version 3.8 it contains this line of code:
https://github.com/square/okhttp/blob/parent-3.8.0/okhttp/src/main/java/okhttp3/ConnectionSpec.java#L113

And in 3.10:
https://github.com/square/okhttp/blob/parent-3.10.0/okhttp/src/main/java/okhttp3/ConnectionSpec.java#L113

Note that 3.10 has no executable code!

@chwnFlyPig
Copy link

this issue still exists in okhttp3.12.1.
here is my logs:
TlsVersion-crash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug in existing code
Projects
None yet
Development

No branches or pull requests