-
Notifications
You must be signed in to change notification settings - Fork 25k
Allow network requests to finish when app is sent to background #31838
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
Allow network requests to finish when app is sent to background #31838
Conversation
91a1621 to
772e843
Compare
772e843 to
163776f
Compare
163776f to
4791093
Compare
Base commit: eddefec |
7be1ace to
807ad5b
Compare
|
PR build artifact for 807ad5b is ready. |
807ad5b to
c2cd30e
Compare
|
kind bump here 👋 |
|
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
This change allows network requests to be executed in background safely.
In certain conditions iOS HTTP requests are being terminated with this
error:
```
Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost."
```
While working on this issue I discovered this happens when app is
brought to background (sometimes several times). This is easy to
reproduce on a real device, but doesn't happen often in simulator.
1. Create sample express server:
```js
const express = require('express');
const app = express();
const port = 9999;
app.get('/', (req, res) => {
setTimeout(() => {
res.send('Hello World!');
}, 20000);
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});
```
2. Run the following code in react-native app:
```
const App = () => {
return (
<View style={{margin: 30}}>
<Button
onPress={() => {
console.log('sending a request');
axios
.get('http://192.168.0.110:9999')
.then(r => {
console.log('response', r.data);
})
.catch(e => {
console.log('error', e);
});
}}
title="REQUEST"
/>
</View>
);
};
```
3. Hit "REQUEST" button and send app to background few times for a few
seconds each. The request should succeed in the end.
c2cd30e to
6c3d97f
Compare
This pr is still relevant. Can it be looked at please? I'm not sure how others are dealing with the fact that network requests hang up when the app goes to background. We have to carry patch with "patch package" in all our apps because of this problem. |
|
i am so sad about this problem..... hope this pr should merge.... |
|
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
|
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
|
This PR was closed because it has been stalled for 7 days with no activity. |

Summary
This change allows network requests to be executed in background safely.
In certain conditions iOS HTTP requests are being terminated with this
error:
While working on this issue I discovered this happens when app is
brought to background (sometimes several times).
Changelog:
[iOS] [Fixed] - Fix random network errors happening when application is in background
Test Plan
Create sample express server:
Run the following code in react-native app:
Hit "REQUEST" button and send app to background few times for a few seconds each. The request should succeed in the end.