Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Double reporting of background geolocation #1449

Open
2 of 3 tasks
al-muammar opened this issue Mar 17, 2025 · 2 comments
Open
2 of 3 tasks

[Bug]: Double reporting of background geolocation #1449

al-muammar opened this issue Mar 17, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@al-muammar
Copy link

al-muammar commented Mar 17, 2025

Required Reading

  • Confirmed

Plugin Version

4.16.9

Flutter Doctor

$ flutter doctor                                                                                                                                                                             11:46:11
Doctor summary (to see all details, run flutter doctor -v):
[!] Flutter (Channel [user-branch], 3.27.4, on macOS 15.3.1 24D70 darwin-arm64, locale en-GB)
    ! Flutter version 3.27.4 on channel [user-branch] at /Users/muammar/Development/flutter
      Currently on an unknown channel. Run `flutter channel` to switch to an official channel.
      If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/setup.
    ! Upstream repository unknown source is not a standard remote.
      Set environment variable "FLUTTER_GIT_URL" to unknown source to dismiss this error.
[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2024.2)
[✓] VS Code (version 1.96.2)
[✓] VS Code (version 1.99.0-insider)
[✓] Connected device (4 available)
[✓] Network resources

Mobile operating-system(s)

  • iOS
  • Android

Device Manufacturer(s) and Model(s)

SM-A525F

Device operating-systems(s)

Android 13

What happened?

Geolocation tracking turned-on twice and was sending coordinates twice to the server

Plugin Code and/or Config

It seems that there was a race condition and background geolocation start was called twice. At the same time our code looks as follows:

  Future<void> start() async {
    final state = await BackgroundGeolocation.state;
    if (state.enabled) {
      return;
    }
    await BackgroundGeolocation.start();
  }

Then one stream collecting background geolocation was actively sending everything to the server, the other one simply collected and saved to the local database. At some point the collecting stream started sending the data to the server and data duplication finished. It seems like a weird situation

Relevant log output

@al-muammar al-muammar added the bug Something isn't working label Mar 17, 2025
@christocracy
Copy link
Member

The native SDK is implemented as a Singleton.

It is impossible to have two instances independently running and recording location.

@christocracy
Copy link
Member

background geolocation start was called twice

You can call .start() a hundred times, the plug-in doesn’t care. It does not affect the performance of the plug-in.

Try it yourself and see.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants