Skip to content

Excessive number of pending callbacks: 501. Some pending callbacks that might have leaked by never being called from native #349

Open
@FaizanAventior

Description

@FaizanAventior

Environment

"react-native": "0.73.9",
"@react-native-community/geolocation": "^3.4.0",
"react": "18.2.0",
"react-native-background-actions": "^4.0.1",

const updateLocation = async () => {
// webSocketService.connect();
const deviceId = await getAndroidId();
const gpsInterval = store.getState().appInfo.appInfoRelatedState.interval;
console.log(gpsInterval, 'gps');

while (BackgroundService.isRunning()) {
try {
webSocketService.connect();
// webSocketService.connect();
// webSocketService.flushGPSDataBuffer();
const unixTimestamp = Date.now();
// const latestGPSData = webSocketService.dequeueGPSData();
let latestGPSData: AppInfoNS.GPSData = {
dev_id: deviceId,
latitude: 0,
longitude: 0,
timestamp: unixTimestamp,
};

  Geolocation.getCurrentPosition(
    position => {
      latestGPSData.latitude = position.coords.latitude;
      latestGPSData.longitude = position.coords.longitude;
      if (
        typeof latestGPSData.latitude == 'number' &&
        typeof latestGPSData.longitude == 'number' &&
        !isNaN(latestGPSData.latitude) &&
        !isNaN(latestGPSData.longitude) &&
        latestGPSData.latitude != 0 &&
        latestGPSData.longitude != 0
      ) {
        console.log('latestGPSData object', latestGPSData);
       sending data to server 
      } else {
        console.warn('Invalid or no GPS data to process.');
      }
    },
    error => {
      console.log(`Geolocation error: ${error.message}`);
    },
    {
      enableHighAccuracy: true,
      timeout: 30000,
      maximumAge: 15000,
    },
  );
} catch (error) {
  console.error('Error fetching interval from Remote Config:', error);
}
// Default to 60 seconds if Remote Config is invalid

console.log(`Next GPS data fetch scheduled after ${gpsInterval}ms.`);
await new Promise(resolve => setTimeout(resolve, gpsInterval));

}
};
Geolocation.setRNConfiguration({
skipPermissionRequests: true,
enableBackgroundLocationUpdates: false,
authorizationLevel: 'whenInUse',
locationProvider: 'android',
});

React.useEffect(() => {
const startGPSBackgroundService = async () => {
const hasPermission = await PermissionsAndroid.check(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
);
if (hasPermission) {
const hasDayBegin = homeState.beginReading;
if (hasDayBegin && !homeState.endReading) {
const startBackgroundService = async () => {
if (!BackgroundService.isRunning()) {
await BackgroundService.start(updateLocation, optionsDetails);
console.log('Background service started');
}
};
startBackgroundService(); // Call it once
}
{
if (BackgroundService.isRunning() && homeState.endReading) {
await BackgroundService.stop();
console.log('background stop');
}
}
}
};
startGPSBackgroundService();
}, [homeState.beginReading, homeState.endReading]);

Platforms

This Issue i was able to see on Andorid Side as our App is only for Android User

Versions

  • Android:
  • iOS:
  • react-native-geolocation:
  • react-native:
  • react:

Description

Excessive number of pending callbacks: 501. Some pending callbacks that might have leaked by never being called from native code: {"4347":{"module":"RNCGeolocation","method":"getCurrentPosition"},"4348":{"module":"RNCGeolocation","method":"getCurrentPosition"},"4349":{"module":"RNCGeolocation","method":"getCurrentPosition"},"4352":{"module":"RNCGeolocation","method":"getCurrentPosition"},"4353":{"module":"RNCGeolocation","method":"getCurrentPosition"},"4354":{},"4355":{"module":"RNCGeolocation","method":"getCurrentPosition"},"4358":{"module":"RNCGeolocation","method":"getCurrentPosition"},"4359":{"module":"RNCGeolocation","method":"getCurrentPosition"},"5090":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5096":{"module":"ReactNativePushNotification","method":"createChannel"},"5259":{},"5260":{},"5261":{},"5262":{},"5263":{},"5264":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5265":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5266":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5267":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5268":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5269":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5270":{"module":"RNBackgroundActions","method":"start"},"5271":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5272":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5273":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5274":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5275":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5276":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5277":{"module":"PermissionsAndroid","method":"requestPermission"},"5278":{},"5279":{},"5280":{},"5281":{},"5282":{},"5283":{"module":"RNCGeolocation","method":"getCurrentPosition"},"5284":{"module":"RNCGeolocation","method":"getCurrentPosition"},"5285":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5286":{"module":"PermissionsAndroid","method":"requestPermission"},"5287":{"module":"RNCGeolocation","method":"getCurrentPosition"},"5288":{"module":"RNCGeolocation","method":"getCurrentPosition"},"5289":{"module":"RNCGeolocation","method":"getCurrentPosition"},"5290":{},"5291":{},"5292":{"module":"PermissionsAndroid","method":"requestPermission"},"5293":{"module":"RNCGeolocation","method":"getCurrentPosition"},"5294":{"module":"PermissionsAndroid","method":"requestPermission"},"5295":{"module":"PermissionsAndroid","method":"requestPermission"},"5310":{"module":"PermissionsAndroid","method":"shouldShowRequestPermissionRationale"},"5311":{"module":"RNCGeolocation","method":"getCurrentPosition"},"...(truncated keys)...":451}

Reproducible Demo

in our app if we open the app and our foregorund service is started so that we can send gps lat long on server end every after 30-40 seconds
after satrting the app lets its send lat lon 10 times
then keep the app in background for 2 mins then turn of mobile location atleast for 10 mins
stop the background service in mobile then open the app
then this will appears

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions