@@ -263,6 +263,12 @@ class WebSocket with TimerHelper {
263263 setTimer (
264264 Duration (milliseconds: delay),
265265 () async {
266+ // If the user is null, it means either the connection was never
267+ // established or it was disconnected manually.
268+ //
269+ // In either case, we should not attempt to reconnect.
270+ if (_user == null ) return ;
271+
266272 final uri = await _buildUri (
267273 refreshToken: refreshToken,
268274 includeUserDetails: false ,
@@ -475,21 +481,18 @@ class WebSocket with TimerHelper {
475481 /// Disconnects the WS and releases eventual resources
476482 void disconnect () {
477483 if (connectionStatus == ConnectionStatus .disconnected) return ;
478-
479- _resetRequestFlags (resetAttempts: true );
480-
481484 _connectionStatus = ConnectionStatus .disconnected;
482485
483486 _logger? .info ('Disconnecting web-socket connection' );
484487
488+ _manuallyClosed = true ;
489+ _resetRequestFlags (resetAttempts: true );
490+ _stopMonitoringEvents ();
491+
485492 // resetting user
486493 _user = null ;
487494 connectionCompleter = null ;
488495
489- _stopMonitoringEvents ();
490-
491- _manuallyClosed = true ;
492-
493496 _closeWebSocketChannel ();
494497 }
495498}
0 commit comments