Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/stream_chat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Upcoming

🐞 Fixed

- Fixed `WebSocket` race condition where reconnection could access null user during disconnect.

## 9.14.0

🐞 Fixed
Expand Down
17 changes: 10 additions & 7 deletions packages/stream_chat/lib/src/ws/websocket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,12 @@ class WebSocket with TimerHelper {
setTimer(
Duration(milliseconds: delay),
() async {
// If the user is null, it means either the connection was never
// established or it was disconnected manually.
//
// In either case, we should not attempt to reconnect.
if (_user == null) return;

final uri = await _buildUri(
refreshToken: refreshToken,
includeUserDetails: false,
Expand Down Expand Up @@ -475,21 +481,18 @@ class WebSocket with TimerHelper {
/// Disconnects the WS and releases eventual resources
void disconnect() {
if (connectionStatus == ConnectionStatus.disconnected) return;

_resetRequestFlags(resetAttempts: true);

_connectionStatus = ConnectionStatus.disconnected;

_logger?.info('Disconnecting web-socket connection');

_manuallyClosed = true;
_resetRequestFlags(resetAttempts: true);
_stopMonitoringEvents();

// resetting user
_user = null;
connectionCompleter = null;

_stopMonitoringEvents();

_manuallyClosed = true;

_closeWebSocketChannel();
}
}