react-native-background-timer icon indicating copy to clipboard operation
react-native-background-timer copied to clipboard

Background task creates the risk of termination

Open zoolle opened this issue 4 years ago • 6 comments

I have opened the app and on initial load I create a set interval to send the location to backend every 5 seconds. I left the app in foreground and then in Xcode logs started to show me this

2021-11-25 14:41:34.367850+0000 Driver[3314:522530] [BackgroundTask] Background Task 5 ("RNBackgroundTimer"), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this. 2021-11-25 14:42:02.242027+0000 Driver[3314:523175] [tcp] tcp_output [C8.1:3] flags=[R.] seq=1461532209, ack=806701271, win=2047 state=CLOSED rcv_nxt=806701271, snd_una=1461532132 2021-11-25 14:44:59.632334+0000 Driver[3314:523177] [tcp] tcp_input [C18.1:3] flags=[R] seq=2256668869, ack=0, win=0 state=LAST_ACK rcv_nxt=2256668869, snd_una=1943136650 2021-11-25 14:44:59.632865+0000 Driver[3314:523177] [tcp] tcp_input [C18.1:3] flags=[R] seq=2256668869, ack=0, win=0 state=CLOSED rcv_nxt=2256668869, snd_una=1943136650 2021-11-25 14:44:59.633033+0000 Driver[3314:523177] [tcp] tcp_input [C18.1:3] flags=[R] seq=2256668869, ack=0, win=0 state=CLOSED rcv_nxt=2256668869, snd_una=1943136650

Any idea why I get this and how can I avoid it?

zoolle avatar Nov 25 '21 14:11 zoolle

Same

brunomartinezciompi avatar Dec 20 '21 13:12 brunomartinezciompi

Same issue.

guest2acute avatar Jan 28 '22 12:01 guest2acute

As far as I understand it you can just run code up to 30 seconds after the app enters background, and then you can only fire events again in a period of 15 minutes (also 30 seconds).

You could start the timer again with https://github.com/transistorsoft/react-native-background-fetch which runs code every 15 minutes, but also it could be less depending on the hidden iOS background algorithm which depends on how often a App is used by the user (less use, less frequent background runtime)

Please correct me when I'm wrong, still figuring this background stuff out with react-native.

Tim4497 avatar Mar 23 '22 13:03 Tim4497

Has anyone faced this warning and seen timer performance issues with iOS in production? I'm getting timer issues with iOS but works seemingly fine on Android.

dillonkelley avatar May 09 '22 20:05 dillonkelley

@Tim4497 So does this mean we have to use this package in conjunction with react-native-background-fetch? Or should we solely use react native background fetch for background tasks?

Irongade avatar Aug 03 '22 22:08 Irongade

@Tim4497 So does this mean we have to use this package in conjunction with react-native-background-fetch? Or should we solely use react native background fetch for background tasks?

I used:

BackgroundFetch from 'expo-background-fetch'; TaskManager from 'expo-task-manager';

and

queue, { Worker } from 'react-native-job-queue';

in the end.

You can use them in bare rn projects, so no expo required

Tim4497 avatar Aug 03 '22 23:08 Tim4497