[Question] Timing out an async call
See original GitHub issueIt is required behaviour on iOS to call the finish event within 30sec of starting the background fetch event. However, it is thinkable that my async call to the server does not receive a response (result or error) from the server within 30 seconds and the code keeps waiting, leading to the app being killed. Intuitively I would have used a javascript timeout (setTimeout), which calls the finish event after say 25 seconds. However, the timeout does not seem to work in background mode and the function defined in the timeout is only called once the app returns to foreground. How do you work around this issue? Or am I just not understanding something?
Your Environment
- Plugin version: 2.4.6
- Platform: both
- OS version: android 8, iOS 12
- Device manufacturer / model: Samsung a3, iPhone SE
- React Native version (
react-native -v
): 0.57.8 - Plugin config
Expected Behavior
function defined in setTimeout is called after the defined time in background mode
Actual Behavior
function defined in setTimeout is called only when app returns to foreground
Steps to Reproduce
- Define a timeout with setTimeout within the background fetch config
- Move app to background
- Fire a background fetch event
- Wait… After waiting long enough, move app back to foreground, see function inside timeout being called
Context
Timeout async server calls so that iOS doesnt kill the app if server returns nothing within 30sec
Debug logs
N/A
Issue Analytics
- State:
- Created 5 years ago
- Comments:26 (11 by maintainers)
Top GitHub Comments
Decrease your upload size. Apple called this api “fetch”, meaning it’s designed for fetching data from your server (eg latest scores for a sports app).
uploading large files is not what it was designed for.
You call
#finish
when your task is done. If you’re going anasync
call, you need to call#finish
when yourasync
call is “finished”.#finish
is a signal to the native OS that “I am finished. You can end the task now and allow the OS to suspend again”