React-native: Android should use okhttp:3.5.0

Created on 30 Dec 2016  Â·  25Comments  Â·  Source: facebook/react-native

Description

okhttp:3.4.1 has a bug makes working with http/2 + SSL unstable

Reproduction

Have an http/2 + SSL setup and try fetch or XMLHttpRequest API (frisbee or axios) to make an http request, sometimes it hangs at connection

Solution

update okhttp to 3.5.0 and compile react-native again

Additional Information

  • React Native version: 0.40
  • Platform: Android
  • Operating System: MacOS
Locked

Most helpful comment

Developing with react-native is just depressing.

All 25 comments

12-30 19:36:24.581 6266-6563/? E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
                                                 Process: express.whatson, PID: 6266
                                                 java.lang.IllegalStateException: closed
                                                     at okio.RealBufferedSink.write(RealBufferedSink.java:39)
                                                     at okio.ForwardingSink.write(ForwardingSink.java:35)
                                                     at com.facebook.react.modules.network.ProgressRequestBody$1.write(ProgressRequestBody.java:58)
                                                     at okio.RealBufferedSink.flush(RealBufferedSink.java:216)
                                                     at com.facebook.react.modules.network.ProgressRequestBody.writeTo(ProgressRequestBody.java:48)
                                                     at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:47)
                                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
                                                     at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
                                                     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:109)
                                                     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:124)
                                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
                                                     at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
                                                     at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
                                                     at okhttp3.RealCall.access$100(RealCall.java:33)
                                                     at okhttp3.RealCall$AsyncCall.execute(RealCall.java:120)
                                                     at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
                                                     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)

Unfortunately I couldn't update okhttp to 3.5.0 because the latest version of okhttp-ws is 3.4.2
updating to 3.4.2 did not have any affects.

I'm also experiencing issues being able to use okhttp 3.5.0 wth react native

When I run the app I get

FATAL EXCEPTION: AsyncTask #7
    Process: com.app.runapp, PID: 26999
    java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:309)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    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)
        Caused by: java.lang.NoClassDefFoundError: com.facebook.react.devsupport.JSPackagerWebSocketClient
    at com.facebook.react.devsupport.DevServerHelper$1.doInBackground(DevServerHelper.java:122)
    at com.facebook.react.devsupport.DevServerHelper$1.doInBackground(DevServerHelper.java:119)
    at android.os.AsyncTask$2.call(AsyncTask.java:295)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    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) 

My gradle:

    compile 'com.squareup.okhttp3:okhttp:3.5.0'
    compile 'com.squareup.okhttp3:okhttp-urlconnection:3.5.0'

This is due to OkHttp now officially supporting websockets, deprecating the okhttp-ws library (which was relatively unstable). com.facebook.react.devsupport.JSPackagerWebSocketClient uses the old version with okhttp3.ws.WebSocket. This should now just be okhttp3.Websocket, and WebSocketCall is now just merged with Websocket.

My application had to upgrade to okhttp 3.5.0 due to some of the bugs in the okhttp-ws library. Please upgrade to okhttp 3.5.0 😺 .

any fix for this? i'm having same issue as @theseansy

@cinder92 - I'm following this PR now: https://github.com/facebook/react-native/issues/11835

idk why but i'm still getting same issue with RN 0.42.3 :(

Developing with react-native is just depressing.

@el https://github.com/el/react-native,I tried it,doesn‘t work ,any idea?

anyone having any luck with this? i am getting the same error as @theseansy although we are using okhttp3.4.1 in our android app.

I think this can be closed now. On the master branch RN has okhttp 3.8.0.

https://github.com/facebook/react-native/commit/93a1d592d61b229d3dafe57d1590d286312cc0bf

But when the master branch will be released??? I tried to use it but was unsucessful

On master branch, okhttp was reverted to 3.6.0. Anybody can tell me why making this change? OkHttp 3.8.0 release recovers a bug gracefully on Huawei devices running Android 7.0 which can cause app crash . Can master branch work with OkHttp 3.8.0 well ?

Any progress here?

Hi there! This issue is being closed because it has been inactive for a while. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. Either way, we're automatically closing issues after a period of inactivity. Please do not take it personally!

If you think this issue should definitely remain open, please let us know. The following information is helpful when it comes to determining if the issue should be re-opened:

  • Does the issue still reproduce on the latest release candidate? Post a comment with the version you tested.
  • If so, is there any information missing from the bug report? Post a comment with all the information required by the issue template.
  • Is there a pull request that addresses this issue? Post a comment with the PR number so we can follow up.

If you would like to work on a patch to fix the issue, contributions are very welcome! Read through the contribution guide, and feel free to hop into #react-native if you need help planning your contribution.

I have tried okhttp:3.8.0, but didn't succeed。

I do not need to know the POST progress, so I solved the problem by modify this java file:

node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java

NOTICE In order for these changes to take effect,you need to Building React Native from source

here is the code NetworkingModule.java

       // 1.  comment those lines comes after     
} else if (data.hasKey(REQUEST_BODY_KEY_FORMDATA)) {
        ......
//      requestBuilder.method(
//        method,
//        RequestBodyUtil.createProgressRequest(
//          multipartBuilder.build(),
//          new ProgressListener() {
//        long last = System.nanoTime();
//
//        @Override
//        public void onProgress(long bytesWritten, long contentLength, boolean done) {
//          long now = System.nanoTime();
//          if (done || shouldDispatch(now, last)) {
//            ResponseUtil.onDataSend(eventEmitter, requestId, bytesWritten, contentLength);
//            last = now;
//          }
//        }
//      }));

      // 2. and add the following 2 lines
      RequestBody requestBody = multipartBuilder.build();
      requestBuilder.post(requestBody).build();

same issue for me any solution?

@simonracz thanks but how can i upgrade react-native that refer to specific commit or tag when it is not release on NPM?

Any news on this issue?

so... How to solve this problem?? ('·ω·`)

Still seeing this in RN v0.53

Has someone solved this issue? I am still facing it :(

RN v0.51
Okhttp 3.6.0
OS Linux

Was this page helpful?
0 / 5 - 0 ratings