Okhttp: NullPointerException: ssl_session == null

Created on 24 Apr 2017  Â·  11Comments  Â·  Source: square/okhttp

We met a bug recently. the trace log is

java.lang.NullPointerException: ssl_session == null
    at com.android.org.conscrypt.NativeCrypto.SSL_SESSION_cipher(Native Method)
    at com.android.org.conscrypt.OpenSSLSessionImpl.getCipherSuite(OpenSSLSessionImpl.java:320)
    at okhttp3.Handshake.get(Unknown Source)
    at okhttp3.internal.connection.RealConnection.connectTls(Unknown Source)
    at okhttp3.internal.connection.RealConnection.establishProtocol(Unknown Source)
    at okhttp3.internal.connection.RealConnection.buildConnection(Unknown Source)
    at okhttp3.internal.connection.RealConnection.connect(Unknown Source)
    at okhttp3.internal.connection.StreamAllocation.findConnection(Unknown Source)
    at okhttp3.internal.connection.StreamAllocation.findHealthyConnection(Unknown Source)
    at okhttp3.internal.connection.StreamAllocation.newStream(Unknown Source)
    at okhttp3.internal.connection.ConnectInterceptor.intercept(Unknown Source)
    at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
    at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
    at okhttp3.internal.cache.CacheInterceptor.intercept(Unknown Source)
    at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
    at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
    at okhttp3.internal.http.BridgeInterceptor.intercept(Unknown Source)
    at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
    at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(Unknown Source)
    at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
    at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
    at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
    at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
    at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
    at okhttp3.internal.http.RealInterceptorChain.proceed(Unknown Source)
    at okhttp3.RealCall.getResponseWithInterceptorChain(Unknown Source)
    at okhttp3.RealCall.access$100(Unknown Source)
    at okhttp3.RealCall$AsyncCall.execute(Unknown Source)
    at okhttp3.internal.NamedRunnable.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
    at java.lang.Thread.run(Thread.java:818)

What's more, the phone model is m5 and M611D,system version is Android 6.0 .
We think it is a rare problem when tls connect stage. It is great thing when you fixed it! Thanks ~

needs info

Most helpful comment

@swankjesse I think it's a Google Conscrypt bug. Happened on the conscrypt branch, I reported it and there is a fix that should make 1.0.

Happens when you try to use the Session after the remote side closes it. We may want to consider catching this NPE in okhttp, rethrowing as IOException.

https://github.com/google/conscrypt/pull/381/files

All 11 comments

image
+1

I don’t have enough information to take action on this. If you think there’s something OkHttp could do to fix this, please let me know what that is. If it’s something that the device’s vendor should deal with, please report to them.

+1 金立 M5,ROM: Meizu/FLYME,Android 6.0

the same issues appear com.squareup.okhttp3:okhttp:3.6.0 please check again @swankjesse

@ronnie could you help us to isolate and reproduce?

+1 M5 android 6.0 okhttp 3.6.0

Is the problem solved?

I think this needs to be fixed by the device maker.

@swankjesse I think it's a Google Conscrypt bug. Happened on the conscrypt branch, I reported it and there is a fix that should make 1.0.

Happens when you try to use the Session after the remote side closes it. We may want to consider catching this NPE in okhttp, rethrowing as IOException.

https://github.com/google/conscrypt/pull/381/files

i met same bug recently. @swankjesse said it is a Google Conscrypt bug, i follow @yschimke's guide,wrote a class NetExceptionHandlerInterceptor,then i add NetExceptionHandlerInterceptor to okhttpClient's NetworkInterceptor,so it handle all Exception and rethrowing as IOException,i think this method can resolve the problem.

public class NetExceptionHandlerInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        try {
            return chain.proceed(chain.request());
        } catch (Exception e) {
            throw new IOException(e.getMessage());
        }
    }
}

//add  NetExceptionHandlerInterceptor to OkHttpClient.Builder.
 OkHttpClient.Builder builder = new OkHttpClient
                .Builder();
 builder.addNetworkInterceptor(new NetExceptionHandlerInterceptor());

For my app its about 500 crashes per week and all of it happens only on Meizu M5 on Android 6. Suggested workaround based on NetExceptionHandlerInterceptor does not help. But if its really Google Conscrypt bug then probably it could be fixed using conscrypt lib

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SandroMachado picture SandroMachado  Â·  3Comments

SElab2019 picture SElab2019  Â·  3Comments

yschimke picture yschimke  Â·  3Comments

TheLester picture TheLester  Â·  3Comments

yschimke picture yschimke  Â·  3Comments