mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-11 16:57:39 +00:00
The grace-period unsubscribe in LifecycleAwareKeyDataSourceSubscription ran on the composition scope from rememberCoroutineScope(), whose dispatcher is coupled to the UI frame clock. When the app is backgrounded the frame clock stops ticking, so the pending unsubscribe could be starved and never fire. Because closing the REQ is what drives the relay disconnect (via desiredRelays -> RelayPool.updatePool), the connection could linger indefinitely. This is most visible on the relay feed, whose dedicated one-off relay is kept alive by nothing else. Drive the grace timer from Lifecycle.currentStateFlow on a dedicated Dispatchers.Default scope instead. collectLatest cancels the pending delay automatically when the lifecycle returns to STARTED, preserving the 30s app-switch grace while ensuring the timer fires reliably in the background. https://claude.ai/code/session_01SesftJphLwvLtn1fJB5zx8