Skip to content

Fix excessive location uploads (two critical issues)#106

Open
Perlover wants to merge 1 commit intotraccar:mainfrom
Perlover:fix/race-condition-excessive-uploads
Open

Fix excessive location uploads (two critical issues)#106
Perlover wants to merge 1 commit intotraccar:mainfrom
Perlover:fix/race-condition-excessive-uploads

Conversation

@Perlover
Copy link
Copy Markdown

Problem Analysis (from server logs):

  • 354,527 POST requests in 24 hours
  • Only 37,090 unique timestamps
  • Average: 9-10 duplicates per location
  • Some locations sent up to 22 times over 8+ hours
  • Location from 08:55:51 sent at: 00:00, 01:50, 03:40, 05:32, 07:44

Root Causes:

  1. Headless Isolate Cache Issue

    • Headless tasks run in separate Dart isolates on Android
    • LocationCache._last (static in-memory) is null in each isolate
    • When cache is null, _shouldDelete() returns false
    • Result: NO filtering applied → locations sent every 1-2 seconds
    • 37k locations/day instead of normal 2k
  2. Locations Not Deleted After Sync (CRITICAL)

    • autoSync: false with manual sync() calls
    • Plugin accumulates locations in database indefinitely
    • Each sync() resends ALL accumulated locations
    • Database grows: same location sent 2hrs later, 4hrs later, etc.
    • Result: 37k × 9 = 354k requests/day

Solutions:

  1. Fallback filtering when cache is null

    • Check SharedPreferences directly for lastTimestamp
    • Apply fastestInterval filtering even without in-memory cache
    • Prevents excessive location generation in headless mode
  2. Explicit location deletion after sync

    • Call destroyLocation() immediately after successful sync()
    • Prevents database accumulation
    • Each location sent only once

Impact:

  • Before: 354k requests/day (37k locations × 9 duplicates)
  • After: ~2k requests/day (normal operation)
  • Reduction: ~99.4%

🤖 Generated with Claude Code

Problem Analysis (from server logs):
- 354,527 POST requests in 24 hours
- Only 37,090 unique timestamps
- Average: 9-10 duplicates per location
- Some locations sent up to 22 times over 8+ hours
- Location from 08:55:51 sent at: 00:00, 01:50, 03:40, 05:32, 07:44

Root Causes:

1. **Headless Isolate Cache Issue**
   - Headless tasks run in separate Dart isolates on Android
   - LocationCache._last (static in-memory) is null in each isolate
   - When cache is null, _shouldDelete() returns false
   - Result: NO filtering applied → locations sent every 1-2 seconds
   - 37k locations/day instead of normal 2k

2. **Locations Not Deleted After Sync** (CRITICAL)
   - autoSync: false with manual sync() calls
   - Plugin accumulates locations in database indefinitely
   - Each sync() resends ALL accumulated locations
   - Database grows: same location sent 2hrs later, 4hrs later, etc.
   - Result: 37k × 9 = 354k requests/day

Solutions:

1. **Fallback filtering when cache is null**
   - Check SharedPreferences directly for lastTimestamp
   - Apply fastestInterval filtering even without in-memory cache
   - Prevents excessive location generation in headless mode

2. **Explicit location deletion after sync**
   - Call destroyLocation() immediately after successful sync()
   - Prevents database accumulation
   - Each location sent only once

Impact:
- Before: 354k requests/day (37k locations × 9 duplicates)
- After: ~2k requests/day (normal operation)
- Reduction: ~99.4%

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@Perlover
Copy link
Copy Markdown
Author

This is the final commit from Claude with the analysis and fix. I gave him my entire log file from that day for analysis — he went through it and produced this analysis and patch.

rossigee added a commit to rossigee/traccar-client that referenced this pull request Feb 25, 2026
…sues)

- Fix headless isolate cache issue causing unfiltered location uploads
- Add explicit location deletion after sync to prevent accumulation
- Reduce from 354k requests/day to ~2k requests/day (99.4% reduction)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants