Modern Apps git

← Modern-Apps.git

share: fix startReceiving wedge on startup failure

Commit
888409e1a490ac714d92f16fe163eeba55df12ee
Author
Vayun Mathur <[email protected]>
When
2026-11-08 02:18 UTC (28 days ago)
Parents
9acca39
startReceiving set receiving = true before doing the fallible work.
If link selection or server.start() threw (port bind conflict,
Mosey HAL failure), the flag stayed true forever: every later call
returned early, so receiving could never be retried without an app
restart — and the link refcount taken by acquire() leaked, pinning
the Mosey radio.

Set the flag only after the server is up and advertising, and
balance acquire() with release() on the failure path before
rethrowing. (No dedicated test: AirDropHttpServer is a concrete
field, not injectable; the existing start/stop idempotency test in
AirDropSenderTest covers the happy path, run green.)

Verified with :share:testDevUnitTest (platform.airdrop package).

Diff

share/src/main/java/com/vayunmathur/share/platform/airdrop/AirDropController.kt
diff --git a/share/src/main/java/com/vayunmathur/share/platform/airdrop/AirDropController.kt b/share/src/main/java/com/vayunmathur/share/platform/airdrop/AirDropController.ktindex f5448de7d8..2d81cb91e3 100644--- a/share/src/main/java/com/vayunmathur/share/platform/airdrop/AirDropController.kt+++ b/share/src/main/java/com/vayunmathur/share/platform/airdrop/AirDropController.kt@@ -85,10 +85,15 @@ class AirDropController(      suspend fun startReceiving() {         if (receiving) return-        receiving = true         val link = acquire()-        val port = server.start()-        discovery.advertise(AirDropMessages.randomShortId(), port, link.network)+        try {+            val port = server.start()+            discovery.advertise(AirDropMessages.randomShortId(), port, link.network)+            receiving = true+        } catch (e: Exception) {+            release()+            throw e+        }     }      suspend fun stopReceiving() {