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

Duplicate location data received

Open rahulrai-osg opened this issue 2 years ago • 6 comments

Your Environment

  • Plugin version: 4.4.4
  • Platform: Android
  • OS version: 8.1
  • Device manufacturer / model: Oppo A3
  • React Native version (react-native -v): 0.64.0
  • Plugin config
BackgroundGeolocation.ready({
  desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
  stopTimeout: 5,
  stationaryRadius: 10,
  // debug: true, // <-- enable this hear sounds for background-geolocation life-cycle.
  // logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
  stopOnTerminate: false,   // <-- Allow the background-service to continue tracking when user closes the app.
  startOnBoot: true,        // <-- Auto start tracking when device is powered-up.
  foregroundService: true,
  url: Config.GEOLOCATION_URL +  'geolocations/',
  batchSync: true,       // <-- [Default: false] Set true to sync locations to server in a single HTTP request.
  maxBatchSize: 30,
  autoSyncThreshold: 1,
  autoSync: true,         // <-- [Default: true] Set true to sync each location to server as it arrives.
  backgroundPermissionRationale: {
    title: "Allow App to access to this device's location in the background",
    message: "In order to track your activity in the background, please enable Allow all the time location permission",
  }
}, (state)=>{
  configureGeolocation()
})

export const configureGeolocation = async () => {
    const credentials = await getCredential();
    const locationConfig = await getLocationConfig();
    if(credentials.Token && locationConfig.track_location){
        BackgroundGeolocation.setConfig({
        distanceFilter: locationConfig.distance_filter,
        headers: {              // <-- Optional HTTP headers
            "Content-Type": "application/json",
            "token": credentials.Token
        },
        params: {               // <-- Optional HTTP params
            "user_type_id": credentials.Phone,
            "device_id": getUniqueId(),
            "source": "app",
            "user_type": "Engineer"
        }
        }).then((state) => {
            console.log("Background Geolocation Ready")
        })
    }
}

Expected Behavior

As per the documentation once the API is success it will DESTROY those records from the SQLite database. And will only receive all the next locations thereafter.

Actual Behavior

Receiving the duplicate location data which was sent in previous API request.

Steps to Reproduce

  1. Reported in production, couldnot reproduce.

Context

User was travelling from one location to other for which the task was assigned. Was also updating few tasks provided for him on the way.

Debug logs

Logs
Since production user device not available with us could not share Android logs. But the backend logs are available. 

{
    'request_body': {'location': [{'is_moving': True, 'uuid': '520cbe60-792c-43d7-ad35-3f5acb1ed11b', 'timestamp': '2022-07-20T05:26:56.886Z', 'odometer': 12240.5, 'coords': {'latitude': 22.4455404, 'longitude': 88.4281667, 'accuracy': 72.9, 'speed': -1, 'speed_accuracy': -1, 'heading': -1, 'heading_accuracy': -1, 'altitude': -51.4, 'altitude_accuracy': 11.3}, 'activity': {'type': 'in_vehicle', 'confidence': 100}, 'battery': {'is_charging': False, 'level': 0.64}, 'extras': {}}, {'is_moving': True, 'uuid': 'dced1772-2852-4028-9475-68118ff70fdd', 'timestamp': '2022-07-20T05:28:52.661Z', 'odometer': 12240.5, 'coords': {'latitude': 22.443241, 'longitude': 88.4289119, 'accuracy': 994, 'speed': -1, 'speed_accuracy': -1, 'heading': -1, 'heading_accuracy': -1, 'altitude': -51.4, 'altitude_accuracy': 11.3}, 'activity': {'type': 'in_vehicle', 'confidence': 100}, 'battery': {'is_charging': False, 'level': 0.63}, 'extras': {}}, {'event': 'motionchange', 'is_moving': True, 'uuid': 'bc8267ed-712a-49d3-a2e3-4d242cc1f2d8', 'timestamp': '2022-07-20T05:28:52.661Z', 'odometer': 12240.5, 'coords': {'latitude': 22.443241, 'longitude': 88.4289119, 'accuracy': 994, 'speed': -1, 'speed_accuracy': -1, 'heading': -1, 'heading_accuracy': -1, 'altitude': -51.4, 'altitude_accuracy': 11.3}, 'activity': {'type': 'in_vehicle', 'confidence': 100}, 'battery': {'is_charging': False, 'level': 0.63}, 'extras': {}}, {'is_moving': True, 'uuid': '48f34745-116b-4dbf-bc0a-b68f75a424ea', 'timestamp': '2022-07-20T05:31:26.830Z', 'odometer': 12240.5, 'coords': {'latitude': 22.4405124, 'longitude': 88.4352074, 'accuracy': 819, 'speed': -1, 'speed_accuracy': -1, 'heading': -1, 'heading_accuracy': -1, 'altitude': -51.4, 'altitude_accuracy': 11.3}, 'activity': {'type': 'in_vehicle', 'confidence': 100}, 'battery': {'is_charging': False, 'level': 0.63}, 'extras': {}}, {'is_moving': True, 'uuid': '7812c7e7-e734-47c0-9feb-a1c8989be7f4', 'timestamp': '2022-07-20T05:33:02.382Z', 'odometer': 12240.5, 'coords': {'latitude': 22.4314231, 'longitude': 88.4506811, 'accuracy': 1144, 'speed': -1, 'speed_accuracy': -1, 'heading': -1, 'heading_accuracy': -1, 'altitude': -51.4, 'altitude_accuracy': 11.3}, 'activity': {'type': 'in_vehicle', 'confidence': 100}, 'battery': {'is_charging': False, 'level': 0.63}, 'extras': {}}, {'is_moving': True, 'uuid': '7b2cb984-18b9-4527-b5ce-d08ae31eed74', 'timestamp': '2022-07-20T05:47:39.816Z', 'odometer': 12240.5, 'coords': {'latitude': 22.3769831, 'longitude': 88.5350714, 'accuracy': 2417, 'speed': -1, 'speed_accuracy': -1, 'heading': -1, 'heading_accuracy': -1, 'altitude': -51.4, 'altitude_accuracy': 11.3}, 'activity': {'type': 'in_vehicle', 'confidence': 100}, 'battery': {'is_charging': False, 'level': 0.62}, 'extras': {}}], 'user_type_id': '124', 'source': 'app', 'user_type': 'Engineer', 'device_id': 'a2291236e93a26a5'}, 
    'timestamp': '2022-07-20 05:48:47.404437'
} => Response 200

{
    'request_body': {'location': [{'is_moving': True, 'uuid': '520cbe60-792c-43d7-ad35-3f5acb1ed11b', 'timestamp': '2022-07-20T05:26:56.886Z', 'odometer': 12240.5, 'coords': {'latitude': 22.4455404, 'longitude': 88.4281667, 'accuracy': 72.9, 'speed': -1, 'speed_accuracy': -1, 'heading': -1, 'heading_accuracy': -1, 'altitude': -51.4, 'altitude_accuracy': 11.3}, 'activity': {'type': 'in_vehicle', 'confidence': 100}, 'battery': {'is_charging': False, 'level': 0.64}, 'extras': {}}, {'is_moving': True, 'uuid': 'dced1772-2852-4028-9475-68118ff70fdd', 'timestamp': '2022-07-20T05:28:52.661Z', 'odometer': 12240.5, 'coords': {'latitude': 22.443241, 'longitude': 88.4289119, 'accuracy': 994, 'speed': -1, 'speed_accuracy': -1, 'heading': -1, 'heading_accuracy': -1, 'altitude': -51.4, 'altitude_accuracy': 11.3}, 'activity': {'type': 'in_vehicle', 'confidence': 100}, 'battery': {'is_charging': False, 'level': 0.63}, 'extras': {}}, {'event': 'motionchange', 'is_moving': True, 'uuid': 'bc8267ed-712a-49d3-a2e3-4d242cc1f2d8', 'timestamp': '2022-07-20T05:28:52.661Z', 'odometer': 12240.5, 'coords': {'latitude': 22.443241, 'longitude': 88.4289119, 'accuracy': 994, 'speed': -1, 'speed_accuracy': -1, 'heading': -1, 'heading_accuracy': -1, 'altitude': -51.4, 'altitude_accuracy': 11.3}, 'activity': {'type': 'in_vehicle', 'confidence': 100}, 'battery': {'is_charging': False, 'level': 0.63}, 'extras': {}}, {'is_moving': True, 'uuid': '48f34745-116b-4dbf-bc0a-b68f75a424ea', 'timestamp': '2022-07-20T05:31:26.830Z', 'odometer': 12240.5, 'coords': {'latitude': 22.4405124, 'longitude': 88.4352074, 'accuracy': 819, 'speed': -1, 'speed_accuracy': -1, 'heading': -1, 'heading_accuracy': -1, 'altitude': -51.4, 'altitude_accuracy': 11.3}, 'activity': {'type': 'in_vehicle', 'confidence': 100}, 'battery': {'is_charging': False, 'level': 0.63}, 'extras': {}}, {'is_moving': True, 'uuid': '7812c7e7-e734-47c0-9feb-a1c8989be7f4', 'timestamp': '2022-07-20T05:33:02.382Z', 'odometer': 12240.5, 'coords': {'latitude': 22.4314231, 'longitude': 88.4506811, 'accuracy': 1144, 'speed': -1, 'speed_accuracy': -1, 'heading': -1, 'heading_accuracy': -1, 'altitude': -51.4, 'altitude_accuracy': 11.3}, 'activity': {'type': 'in_vehicle', 'confidence': 100}, 'battery': {'is_charging': False, 'level': 0.63}, 'extras': {}}, {'is_moving': True, 'uuid': '7b2cb984-18b9-4527-b5ce-d08ae31eed74', 'timestamp': '2022-07-20T05:47:39.816Z', 'odometer': 12240.5, 'coords': {'latitude': 22.3769831, 'longitude': 88.5350714, 'accuracy': 2417, 'speed': -1, 'speed_accuracy': -1, 'heading': -1, 'heading_accuracy': -1, 'altitude': -51.4, 'altitude_accuracy': 11.3}, 'activity': {'type': 'in_vehicle', 'confidence': 100}, 'battery': {'is_charging': False, 'level': 0.62}, 'extras': {}}], 'user_type_id': '124', 'source': 'app', 'user_type': 'Engineer', 'device_id': 'a2291236e93a26a5'}, 
    'timestamp': '2022-07-20 05:48:52.039533',
} => Response 200

rahulrai-osg avatar Jul 25 '22 04:07 rahulrai-osg

This could happen in a rare case where the plugin executed the HTTP request but your app was somehow terminated in the short time before the http response was received by your server.

Or your server did not in fact return return an HTTP 20x response.

christocracy avatar Jul 25 '22 13:07 christocracy

We are sure that we have sent response as 200, you can refer the same in the logs attached to the issue.

It doesn't seems rare as we can see lot of such cases, can we enable something to eliminate these cases?

rahulrai-osg avatar Jul 26 '22 09:07 rahulrai-osg

Nobody has ever reported anything like this in years, so I have no advice.

I will analyze the logs at tracker.transistorsoft.com, where there are tens-of-millions of records from devices all over the world.

christocracy avatar Jul 26 '22 10:07 christocracy

Out of 10M records at https://tracker.transistorsoft.com, I see no duplicate uuid since 2019.

christocracy avatar Jul 28 '22 04:07 christocracy

Hi, Chris it seems that we have exactly the same issue. We are somehow getting duplicate locations which we store in our DB. Here is an example. (BG geolocation is running on IPad in background in this case and it is being stored every ~2 mins) image And it behaves same on Android devices

AndrzejRokosz avatar Aug 04 '22 10:08 AndrzejRokosz

Are you observing the plugin logs with logLevel configured for VERBOSE?

the plugin logs every http request and delete from SQLite. This is most likely an issue i your own code.

you have provided no information (no code, no Config, no device model/version, no plugin version.

christocracy avatar Aug 04 '22 12:08 christocracy