From 024476edc463f6cbdd1330c90b257b1e4aa5c4e2 Mon Sep 17 00:00:00 2001 From: npub1ux8n2yfs8qfvgd75s7kyhar2mztac355v6vmrz4juc9l3msw4pgstums9e Date: Tue, 14 Jul 2026 11:36:09 -0700 Subject: [PATCH] fix(mobile): stabilize relay retry lifecycle Avoid duplicate disconnect callbacks during authentication and invalidate deliberate reconnect callbacks before replacing the socket. Co-authored-by: npub1ux8n2yfs8qfvgd75s7kyhar2mztac355v6vmrz4juc9l3msw4pgstums9e Signed-off-by: npub1ux8n2yfs8qfvgd75s7kyhar2mztac355v6vmrz4juc9l3msw4pgstums9e --- mobile/lib/shared/relay/relay_session.dart | 1 + mobile/lib/shared/relay/relay_socket.dart | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/mobile/lib/shared/relay/relay_session.dart b/mobile/lib/shared/relay/relay_session.dart index 4c3df82fd..6b5e551f2 100644 --- a/mobile/lib/shared/relay/relay_session.dart +++ b/mobile/lib/shared/relay/relay_session.dart @@ -317,6 +317,7 @@ class RelaySessionNotifier extends Notifier { /// Force a reconnect (e.g., returning from background). Future reconnect() async { _reconnectTimer?.cancel(); + ++_connectionGeneration; await _socket?.disconnect(); _resetReconnectBudget(); final config = ref.read(relayConfigProvider); diff --git a/mobile/lib/shared/relay/relay_socket.dart b/mobile/lib/shared/relay/relay_socket.dart index d0fd8426e..11a0b132a 100644 --- a/mobile/lib/shared/relay/relay_socket.dart +++ b/mobile/lib/shared/relay/relay_socket.dart @@ -102,14 +102,18 @@ class RelaySocket { _subscription = _channel!.stream.listen( _handleRawMessage, onError: (Object error) { + final awaitingAuth = + _authCompleter != null && !_authCompleter!.isCompleted; _failAuth(error); _resetConnection(); - _onDisconnected(error); + if (!awaitingAuth) _onDisconnected(error); }, onDone: () { + final awaitingAuth = + _authCompleter != null && !_authCompleter!.isCompleted; _failAuth(null); _resetConnection(); - _onDisconnected(null); + if (!awaitingAuth) _onDisconnected(null); }, );