react-native: App terminated in background when WebSocket is open
I using WebSocket in my app when app move to background it terminated in short time, but I expect OS suspended app. Test on IOS 13.1.2 release mode
log from device
default 21:26:15.204466 +0300 SpringBoard Firing exit handlers for 63390 with context <RBSProcessExitContext; specific: <RBSProcessExitStatus; domain: runningboard (15); code: 0x2182baad>; terminationContext: <RBSTerminateContext: 0x6000032f29c0; code: 0x2182BAAD; explanation: "Timed-out waiting for process [application<org.reactjs.native.example.test-bg>:63390] to invalidate assertion with identifier 4170-63390-4366 and explanation 'Shared Background Assertion 2 for org.reactjs.native.example.test-bg'. Direct this report to owners of that process"; reportType: 0; maxRole: 7; maxTerminationResistance: 3>>
default 21:26:15.207509 +0300 SpringBoard [application<org.reactjs.native.example.test-bg>:63390]* Process exited: <RBSProcessExitContext; specific: <RBSProcessExitStatus; domain: runningboard (15); code: 0x2182baad>; terminationContext: <RBSTerminateContext: 0x6000032f29c0; code: 0x2182BAAD; explanation: "Timed-out waiting for process [application<org.reactjs.native.example.test-bg>:63390] to invalidate assertion with identifier 4170-63390-4366 and explanation 'Shared Background Assertion 2 for org.reactjs.native.example.test-bg'. Direct this report to owners of that process"; reportType: 0; maxRole: 7; maxTerminationResistance: 3>>.
default 21:26:15.207568 +0300 SpringBoard [application<org.reactjs.native.example.test-bg>:63390]* Setting process task state to: Not Running
default 21:26:15.207611 +0300 SpringBoard [application<org.reactjs.native.example.test-bg>:63390]* Setting process visibility to: Unknown
default 21:26:15.207704 +0300 SpringBoard Removing: <FBApplicationProcess: 0x7feb8f7225d0; application<org.reactjs.native.example.test-bg>:63390>
default 21:26:15.207906 +0300 SpringBoard Process exited: <FBApplicationProcess: 0x7feb8f7225d0; application<org.reactjs.native.example.test-bg>:63390> -> <RBSProcessExitContext; specific: <RBSProcessExitStatus; domain: runningboard (15); code: 0x2182baad>; terminationContext: <RBSTerminateContext: 0x6000032f29c0; code: 0x2182BAAD; explanation: "Timed-out waiting for process [application<org.reactjs.native.example.test-bg>:63390] to invalidate assertion with identifier 4170-63390-4366 and explanation 'Shared Background Assertion 2 for org.reactjs.native.example.test-bg'. Direct this report to owners of that process"; reportType: 0; maxRole: 7; maxTerminationResistance: 3>>
default 21:26:15.208345 +0300 SpringBoard Application process state changed for org.reactjs.native.example.test-bg: (null)
full log https://github.com/fonov/rn-websocket/blob/master/device_log.txt
it look like socket can’t finished task and OS kill app
React Native version:
IDEs:
Xcode: 11.0/11A420a - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.2 => 0.61.2
npmGlobalPackages:
react-native-cli: 2.0.1
Steps To Reproduce
https://github.com/fonov/rn-websocket
i create fresh rn project and add this code
componentDidMount() {
const ws = new WebSocket('wss://echo.websocket.org');
ws.onopen = () => {
ws.send('something');
};
ws.onmessage = e => {
setTimeout(() => {
ws.send('something');
}, 1000);
};
ws.onerror = e => {
// an error occurred
console.warn(e.message);
};
ws.onclose = e => {
// connection closed
console.warn(e.code, e.reason);
};
}
in App.js
- clone repo
- run release app from the Home screen rather than from Xcode
- go to home screen
- wait a little bit and app is terminated
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 18 (3 by maintainers)
@xiao99xiao @fonov @radko93 I have reproduced this even on fresh react-native app without any additional code!
Steps:
iOS 13.0 or 13.1 Simulator, Xcode 11.0 or 11.1, react-native@0.61.2
react-native init TestApp
react-native run-ios --simulator="iPhone 11"
I feel a misunderstanding of my issue.
ios suspend app and it absolutely right, i expected this behavior, it part of app life cycle, after suspend app user may return to app and see the state he was in when he left the app, but terminated app is reset inner state
Normally change application life cycles
user open app, state changes from
not running -> inactive -> active
user make some work in app and go to home screen
active -> inactive -> background -> suspended
then user open app again and app move active state
suspended -> inactive -> active
and inner state app not reset, user stay on screen when he stay last time
With WebSocket change application life cycles
user open app, state changes from
not running -> inactive -> active
user make some work in app and go to home screen
active -> inactive -> background -> not running (terminated)
then user open app again
not running -> inactive -> active
inner state is lost
Now if used WebSocket from react-native, app when going in background mode can’t to complete task for a certain number of time and system terminated app and innner state reset
I expect when i use websocket in my app after hide app websoket finish tasks and app move to suspend mode and inner state not reset
it is react-native issue, because websocket is part of RN
Also you can clone my test repo and test self terminated app in background and lost inner state
App-Based Life-Cycle Events https://developer.apple.com/documentation/uikit/app_and_environment/managing_your_app_s_life_cycle?language=objc