Skip to content

[Enhancement]Prevent WebSocket reconnection with expired tokens - #70

Draft
ipavlidakis wants to merge 2 commits into
developfrom
iliaspavlidakis/reconnection-improvements
Draft

[Enhancement]Prevent WebSocket reconnection with expired tokens#70
ipavlidakis wants to merge 2 commits into
developfrom
iliaspavlidakis/reconnection-improvements

Conversation

@ipavlidakis

Copy link
Copy Markdown
Contributor

Summary

Separates token-refresh recovery from automatic WebSocket reconnection.

When a WebSocket disconnects because its token expired, StreamCore now waits for the owning SDK to refresh the token and reconnect explicitly instead of retrying with the existing credentials.

Motivation

An expired token was previously considered automatically reconnectable. This allowed DefaultConnectionRecoveryHandler to call connect() while StreamChat or StreamVideo was still refreshing the token.

That created a race where the WebSocket could reconnect using stale credentials.

Changes

  • Add WebSocketConnectionState.requiresTokenRefresh.
  • Disable automatic reconnection for expired tokens.
  • Preserve the existing invalid-token reconnection behavior.
  • Keep ConnectionStatus as .connecting while token refresh is required.
  • Add tests covering expired-token classification and connection-status mapping.

Recovery contract

  • StreamCore automatically handles network, system, and health-check failures.
  • Product SDKs handle authentication recovery.
  • After successfully refreshing the token, the product SDK explicitly calls connect().

@ipavlidakis ipavlidakis self-assigned this Jul 23, 2026
@ipavlidakis ipavlidakis added the ✅ Feature An issue or PR related to a feature label Jul 23, 2026
@github-actions

Copy link
Copy Markdown
1 Message
📖 Skipping Danger since the Pull Request is classed as Draft/Work In Progress

Generated by 🚫 Danger

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✅ Feature An issue or PR related to a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant