Modern Apps git

← Modern-Apps.git

findfamily: prevent duplicate live WS connections from concurrent startLive

Commit
3110f8bf6788eafff778ab0d41825dcae3ca3047
Author
Vayun Mathur <[email protected]>
When
2026-08-15 00:14 UTC (3 months ago)
Parents
3a2db88

Diff

findfamily/src/main/java/com/vayunmathur/findfamily/util/Networking.kt
diff --git a/findfamily/src/main/java/com/vayunmathur/findfamily/util/Networking.kt b/findfamily/src/main/java/com/vayunmathur/findfamily/util/Networking.ktindex 4a27da2ef5..428fefd8a2 100644--- a/findfamily/src/main/java/com/vayunmathur/findfamily/util/Networking.kt+++ b/findfamily/src/main/java/com/vayunmathur/findfamily/util/Networking.kt@@ -215,6 +215,13 @@ object Networking {      * receive already-decrypted pushes. Reconnects with 1s→15s backoff — there is no      * HTTP fallback, so a dropped socket is simply re-established.      */+    // @Synchronized (with stopLive) makes the check-and-set atomic. onStartCommand can+    // fire concurrently (START_STICKY redelivery, ServiceRestartWorker, BootReceiver),+    // each launching startTracking()->startLive() on Dispatchers.IO. Without this, two+    // invocations both pass the isActive check before either assigns liveJob, leaving+    // two live WebSocket connections — one orphaned and unstoppable. Idempotent: a call+    // while a connection is already live is a no-op.+    @Synchronized     fun startLive(         scope: CoroutineScope,         onLocations: suspend (List<LocationValue>) -> Unit,@@ -303,6 +310,7 @@ object Networking {         }     } +    @Synchronized     fun stopLive() {         liveJob?.cancel(); liveJob = null; wsSession = null         pendingKeyRequests.values.forEach { it.complete(null) }