-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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 crash when network changes from Good to Bad #10423
Comments
@armadilio3 Same issue here. did you got that fixed .? |
@saleeh93 still looking into it, maybe you could describe how you can replicate the crash since I am working on a fairly large project and I am only beginning to pinpoint the exact place of origin for this bug |
@armadilio3 I am also working on large project and I never had that issue when I am testing it, I got those errors from Crashlytics. I didn't even understand when that is coming up |
@armadilio3 Any updates ? |
Same issue here :( |
@lucasfeliciano Still waiting to get this fixed |
So, I have found a temporary solution to this problem which is based on catching the error. After some testing it seems that if you catch the OkHttp error the network request will fail but the app won't crash. So if anyone is interested here is the temporary solution: Edit your MainApplication.java @Override
public void onCreate() {
super.onCreate();
// Setup handler for uncaught exceptions.
Thread.setDefaultUncaughtExceptionHandler (new Thread.UncaughtExceptionHandler()
{
@Override
public void uncaughtException (Thread thread, Throwable e)
{
handleUncaughtException (thread, e);
}
});
}
public void handleUncaughtException (Thread thread, Throwable e)
{
if(e.getMessage() != "closed" || thread.getName() != "OkHttp Dispatcher"){
//Kill the app
System.exit(1);
}else{
//If the OkHttp error occurs we ignore it
Log.e("OkHttp Exception","Received exception " + e.getMessage() + "From thread " + thread.getName());
}
} When I have the time I will look into the root cause of this issue as this is a very poor fix. If I find a solution, will make PR. |
@armadilio3 You are tricky 😉 |
@armadilio3 I use yours,but It`s not running. |
@yunlongz are you building from source? |
@armadilio3's solution works fine for me. But does anyone have any news on this problem? |
Anyone found a real fix ? Problem still exist. |
I tried @armadilio3 issue but I still have same crashes (maybe because I use react-native-fabric). |
I got the same issue, and @armadilio3 solutions is better... |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions. |
It's not stale it's real and happens in my app too as @armadilio3 described it. |
seems related to this bug in okhttp: square/okhttp#3521 That was fixed in okhttp v3.9 but react-native is using v3.6. Can we update the dependency? |
@pmachowski We have the same issue seems like there is a solution in #11016 in the last post. We will test it tomorrow. Is there any finite solution to this problem? |
Same issue for me.. any solution? |
@Pavle93 could you find a solution? |
@ pavle93 the same problem.... could you find a solution? |
…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
…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
@armadilio3's solution works fine for me. but there is an error in it, we have to import android.util.log in MainApplication.java. import android.util.Log; |
Worked for me by adding this line to android/app/build.gradle |
@workostap that works for me too but the problem still persist sometimes. |
To use the latest okhttp you should also upgrade your react native version. You can also solve it by using trying to combine higher versions with lower of each library will lead you to this error |
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions. |
(quick update, we merged a fix for it and we'll probably cherry pick for 0.57-rc3) |
Summary: This change fixes this issue: facebook#10423 Pull Request resolved: facebook#20802 Differential Revision: D9478422 Pulled By: hramos fbshipit-source-id: ce3a098a71c8f50a62b011a2a277004ab7a7b655
Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions. |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information. |
Issue Description
When there are fetch requests made on Android and the network changes from a good connection to a very bad connection, sometimes a crash occurs in RealBufferedSink.java:39.
Steps to Reproduce / Code Snippets
Switching between the networks should reproduce the problem fairly quickly.
Expected Results
The error:
Additional Information
The text was updated successfully, but these errors were encountered: