-
-
Notifications
You must be signed in to change notification settings - Fork 501
Description
After the app has been running for an some time, incoming location messages from friends are received via MQTT but never processed to update their locations on the map and in the friend list. The issue resolves after restarting the app.
Expected Behavior
When location messages arrive from other friends via MQTT, their positions should be updated in the contacts repository and reflected on the map.
Actual Behavior
- MQTT messages from friends are received (visible in logs as Received incoming message: MessageLocation on owntracks/...)
- But the coroutine that processes these messages never executes
- No Contact X moved to... log entries appear
- No MemoryContactsRepo updates occur
- Friends' locations become stale on the map
Steps to Reproduce
- Run the app for an extended period (hours/days)
- Observe that friends' locations stop updating
- Check logs - incoming MQTT messages appear but no processing logs follow
- Restart the app - friends' locations immediately update
Root Cause Analysis
The issue might be in MessageProcessor.kt at lines 471-487. The processIncomingMessage(MessageLocation) method calls scope.launch { ... } to process incoming location messages, but after extended runtime, these coroutines fail to execute.
Key observation from logs:
Working (after fresh start):
[MQTT Call: p10p] MessageProcessor: Received incoming message: MessageLocation on owntracks/friend/gn
[DefaultDispatcher-worker-5] MessageProcessor$processIncomingMessage: Contact owntracks/friend/gn moved to 47.08...
[DefaultDispatcher-worker-5] MemoryContactsRepo: update location for contact owntracks/friend/gn took 270.859us
Broken (after extended runtime):
[MQTT Call: p10p] MessageProcessor: Received incoming message: MessageLocation on owntracks/gisela/gn
// No subsequent processing logs - the scope.launch block never executes
Notably, the outgoing message loop continues to work (messages are sent successfully), but new incoming message coroutines don't launch.
Potential Fix
The ApplicationScope CoroutineScope in ScopeModule.kt is missing the @Singleton annotation:
// Current code (line 21-25):
@ApplicationScope
@Provides
fun providesCoroutineScope(
@CoroutineScopes.DefaultDispatcher defaultDispatcher: CoroutineDispatcher
): CoroutineScope = CoroutineScope(SupervisorJob() + defaultDispatcher)
Should be:
@Singleton // Add this annotation
@ApplicationScope
@Provides
fun providesCoroutineScope(
@CoroutineScopes.DefaultDispatcher defaultDispatcher: CoroutineDispatcher
): CoroutineScope = CoroutineScope(SupervisorJob() + defaultDispatcher)
Without @Singleton, there's no guarantee of a single consistent scope instance. While MessageProcessor is a singleton and receives one scope at injection time, the scope may enter an unhealthy state over time where it cannot launch new coroutines.
Environment
- App version: 2.5.5
- Android version: 16 (BP4A.260105.004.A2)
- Device: Pixel 10 Pro
- Connection mode: MQTT