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

[Android] Fetch - FATAL EXCEPTION: OkHttp Dispatcher #11016

Closed
sreejithr opened this issue Nov 18, 2016 · 11 comments
Closed

[Android] Fetch - FATAL EXCEPTION: OkHttp Dispatcher #11016

sreejithr opened this issue Nov 18, 2016 · 11 comments
Labels
Resolution: Locked This issue was locked by the bot.

Comments

@sreejithr
Copy link
Contributor

sreejithr commented Nov 18, 2016

I haven't figured out a way to reproduce this. But this happens once in a while using fetch(). I'm trying to find a way to reproduce. Will update the issue then. This is the trace I'm getting. Does this ring a bell for anyone?

E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
     Process: com.company.app, PID: 4508
     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:1112)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
          at java.lang.Thread.run(Thread.java:818)

Additional Information

  • React Native version: 0.37
  • Platform: Android
  • Operating System: MacOs
@lacker
Copy link
Contributor

lacker commented Nov 30, 2016

I can't reproduce this either. I think it will be hard to make progress unless we do have a way to repro, so I am going to close this issue. If you find a way to reproduce it then please feel free to reopen!

@lacker lacker closed this as completed Nov 30, 2016
@lijy91
Copy link

lijy91 commented Feb 23, 2017

@locly you try to using axios and stetho, open chrome://inspect and try a http request, always crash.

@litingjun2015
Copy link

I can reproduce it:


let url = APIs.DUANG_LOGIN;  
        console.log(url);
        console.log(formData);

        response = await fetch(url, {
                    method: 'POST',
                    headers: {
                        'Accept': 'application/json',
                        'Content-Type': 'multipart/form-data',
                    },
                    body: formData
                    });
        data = await response.json();
        console.log(data);


Fist Call:
-----------------------------------------------------------------------------------------------------------------------------D/wpa_supplicant( 1146): wlan0: Control interface command 'SIGNAL_POLL'
I/ReactNativeJS(19589): https://open.duangwifi.cn/v1/site/login
I/ReactNativeJS(19589): { _parts: [ [ 'username', 'demo' ], [ 'password', '123456' ] ] }

E/ReactNativeJS(19589): [TypeError: Network request failed]
E/unknown:React(19589): Network request failed, stack:
E/unknown:React(19589): onerror@193:13650
E/unknown:React(19589): value@185:1505
E/unknown:React(19589): value@184:6892
E/unknown:React(19589): value@184:3493
E/unknown:React(19589): <unknown>@184:9942
E/unknown:React(19589): value@76:1364
E/unknown:React(19589): value@30:2818
E/unknown:React(19589): <unknown>@30:1053
E/unknown:React(19589): d@30:127
E/unknown:React(19589): value@30:1025
--------------------------------------------------------------------------------------------------

Second Call:
--------------------------------------------------------------------------------------------------
I/ReactNativeJS(19589): https://open.duangwifi.cn/v1/site/login
I/ReactNativeJS(19589): { _parts: [ [ 'username', 'demo' ], [ 'password', '123456' ] ] }

E/AndroidRuntime(19589): FATAL EXCEPTION: OkHttp Dispatcher
E/AndroidRuntime(19589): Process: com.duanglink.bizappv3, PID: 19589
E/AndroidRuntime(19589): java.lang.IllegalStateException: closed
E/AndroidRuntime(19589):       	at okio.RealBufferedSink.write(RealBufferedSink.java:39)
E/AndroidRuntime(19589):       	at okio.ForwardingSink.write(ForwardingSink.java:35)
E/AndroidRuntime(19589):       	at com.facebook.react.modules.network.ProgressRequestBody$1.write(ProgressRequestBody.java:58)
E/AndroidRuntime(19589):       	at okio.RealBufferedSink.flush(RealBufferedSink.java:216)
E/AndroidRuntime(19589):       	at com.facebook.react.modules.network.ProgressRequestBody.writeTo(ProgressRequestBody.java:48)
E/AndroidRuntime(19589):       	at okhttp3.internal.http.CallServerInterceptor.intercept(CallServerInterceptor.java:47)
E/AndroidRuntime(19589):       	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
E/AndroidRuntime(19589):       	at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:45)
E/AndroidRuntime(19589):       	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
E/AndroidRuntime(19589):       	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
E/AndroidRuntime(19589):       	at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:109)
E/AndroidRuntime(19589):       	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
E/AndroidRuntime(19589):       	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
E/AndroidRuntime(19589):       	at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
E/AndroidRuntime(19589):       	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
E/AndroidRuntime(19589):       	at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:124)
E/AndroidRuntime(19589):       	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:92)
E/AndroidRuntime(19589):       	at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:67)
E/AndroidRuntime(19589):       	at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:170)
E/AndroidRuntime(19589):       	at okhttp3.RealCall.access$100(RealCall.java:33)
E/AndroidRuntime(19589):       	at okhttp3.RealCall$AsyncCall.execute(RealCall.java:120)
E/AndroidRuntime(19589):       	at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
E/AndroidRuntime(19589):       	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
E/AndroidRuntime(19589):       	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
E/AndroidRuntime(19589):       	at java.lang.Thread.run(Thread.java:818)
I/octvm_klo( 3003): klo lock
I/WtEventController( 1599): Receive am_crash event for pid: 19589
W/ActivityManager(  855):   Force finishing activity com.duanglink.bizappv3/.MainActivity

@luongvancong
Copy link

I have same bug. I can not fix theme.

@abrantes01
Copy link

Same issue here.. Do you guys have any news on this ?

@shanyifeng
Copy link

when Debug JS Remotely for a while it will happen

@loiclouvet
Copy link

Seems link to #10423

@cinder92
Copy link

any update on this?

@itinance
Copy link
Contributor

Happens still while debugging on real android device

@kareem-adel
Copy link

I had the same issue with OkHttp, It's related to the connection being kept alive, as a workaround you could close the connection on each call using 'Connection': 'close' header, hopefully it will be fixed soon.

Example:
fetch(backendAPI, { method: 'POST', headers: { 'Connection': 'close' }, body: data })

facebook-github-bot pushed a commit that referenced this issue Feb 3, 2018
…h on closed connection

Summary:
This PR includes the same changes made in #16541, for addressing issues #11853/#15724. It adds upload progress updates for uploads with any request body type, and not just form-data.

Additionally, this PR also includes a commit for fixing an `IllegalStateException` when a user's connection gets closed or times out (issues #10423/#11016). Since this exception was occurring within the progress updates logic, it started being thrown more frequently as a result of adding progress updates to all uploads, which was why the original PR was reverted.

To test the upload progress updates, run the following JS to ensure events are now being dispatched:
```
const fileUri = 'file:///my_file.dat';
const url = 'http://my_post_url.com/';
const xhr = new XMLHttpRequest();

xhr.upload.onprogress = (event) => {
    console.log('progress: ' + event.loaded + ' / ' + event.total);
}

xhr.onreadystatechange = () => {if (xhr.readyState === 4) console.log('done');}

console.log('start');

xhr.open('POST', url);

// sending a file (wasn't sending progress)
xhr.setRequestHeader('Content-Type', 'image/jpeg');
xhr.send({ uri: fileUri });

// sending a string (wasn't sending progress)
xhr.setRequestHeader('Content-Type', 'text/plain');
xhr.send("some big string");

// sending form data (was already working)
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
const formData = new FormData(); formData.append('test', 'data');
xhr.send(formData);
```

To test the crash fix:
In the RN Android project, before this change, set a breakpoint at `mRequestBody.writeTo(mBufferedSink);` of `ProgressRequestBody`, and wait a short while for a POST request with a non-null body to time out before resuming the app. Once resumed, if the connection was closed (the `closed` variable will be set to true in `RealBufferedSink`), an `IllegalStateException` will be thrown, which crashes the app. After the changes, an `IOException` will get thrown instead, which is already being properly handled.

As mentioned above, includes the same changes as #16541, with an additional commit.

[ANDROID] [BUGFIX] [XMLHttpRequest] - Added progress updates for all XMLHttpRequest upload types / fix crash on closed connection

Previously, only form-data request bodies emitted upload progress updates. Now, other request body types will also emit updates. Also, Android will no longer crash on certain requests when user has a poor connection.

Addresses issues: 11853/15724/10423/11016
Closes #17312

Differential Revision: D6712377

Pulled By: mdvacca

fbshipit-source-id: bf5adc774703e7e66f7f16707600116f67201425
Plo4ox pushed a commit to Plo4ox/react-native that referenced this issue Feb 17, 2018
…h on closed connection

Summary:
This PR includes the same changes made in facebook#16541, for addressing issues facebook#11853/facebook#15724. It adds upload progress updates for uploads with any request body type, and not just form-data.

Additionally, this PR also includes a commit for fixing an `IllegalStateException` when a user's connection gets closed or times out (issues facebook#10423/facebook#11016). Since this exception was occurring within the progress updates logic, it started being thrown more frequently as a result of adding progress updates to all uploads, which was why the original PR was reverted.

To test the upload progress updates, run the following JS to ensure events are now being dispatched:
```
const fileUri = 'file:///my_file.dat';
const url = 'http://my_post_url.com/';
const xhr = new XMLHttpRequest();

xhr.upload.onprogress = (event) => {
    console.log('progress: ' + event.loaded + ' / ' + event.total);
}

xhr.onreadystatechange = () => {if (xhr.readyState === 4) console.log('done');}

console.log('start');

xhr.open('POST', url);

// sending a file (wasn't sending progress)
xhr.setRequestHeader('Content-Type', 'image/jpeg');
xhr.send({ uri: fileUri });

// sending a string (wasn't sending progress)
xhr.setRequestHeader('Content-Type', 'text/plain');
xhr.send("some big string");

// sending form data (was already working)
xhr.setRequestHeader('Content-Type', 'multipart/form-data');
const formData = new FormData(); formData.append('test', 'data');
xhr.send(formData);
```

To test the crash fix:
In the RN Android project, before this change, set a breakpoint at `mRequestBody.writeTo(mBufferedSink);` of `ProgressRequestBody`, and wait a short while for a POST request with a non-null body to time out before resuming the app. Once resumed, if the connection was closed (the `closed` variable will be set to true in `RealBufferedSink`), an `IllegalStateException` will be thrown, which crashes the app. After the changes, an `IOException` will get thrown instead, which is already being properly handled.

As mentioned above, includes the same changes as facebook#16541, with an additional commit.

[ANDROID] [BUGFIX] [XMLHttpRequest] - Added progress updates for all XMLHttpRequest upload types / fix crash on closed connection

Previously, only form-data request bodies emitted upload progress updates. Now, other request body types will also emit updates. Also, Android will no longer crash on certain requests when user has a poor connection.

Addresses issues: 11853/15724/10423/11016
Closes facebook#17312

Differential Revision: D6712377

Pulled By: mdvacca

fbshipit-source-id: bf5adc774703e7e66f7f16707600116f67201425
@code-matt
Copy link

code-matt commented Apr 20, 2018

I was getting this today, app was working fine on some androids but not Galaxy S#
to fix:

open android/app/app.iml

change the following lines (bumping version for okhttp to 3.8)

<orderEntry type="library" exported="" name="com.squareup.okhttp3:okhttp:3.8.0@jar" level="project" />

<orderEntry type="library" exported="" name="com.squareup.okhttp3:okhttp-urlconnection:3.8.0@jar" level="project" />

and its working now

@facebook facebook locked as resolved and limited conversation to collaborators May 24, 2018
@react-native-bot react-native-bot added the Resolution: Locked This issue was locked by the bot. label Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Resolution: Locked This issue was locked by the bot.
Projects
None yet
Development

No branches or pull requests