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); }, );