-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix connection not resuming after guest user goes to background #3483
Fix connection not resuming after guest user goes to background #3483
Conversation
SDK Size
|
SDK Performance
|
Quality Gate passedIssues Measures |
@@ -456,7 +456,6 @@ public class ChatClient { | |||
/// Disconnects the chat client from the chat servers. No further updates from the servers | |||
/// are received. | |||
public func disconnect(completion: @escaping () -> Void) { | |||
connectionRecoveryHandler?.stop() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be safe because recovery handler checks for current connection state and does not attempt to reconnect if the state is disconnected
with userInitiated
. 🤔
var canReconnectFromOffline: Bool {
…
switch webSocketClient.connectionState {
case .disconnected(let source) where source == .userInitiated:
return false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes exactly the reconnection handler although alive, it won't do nothing
🔗 Issue Links
#3338
https://linear.app/stream/issue/IOS-75/[reconnection]-[github]-websocket-disconnectes-when-guest-user-comes
🎯 Goal
Fixes connection not resuming after guest user goes to background
📝 Summary
🛠 Implementation
The root of the problem was that, in a previous PR, we introduced stopping the recovery handler on
disconnect()
.The reason why this is problematic is because of how our
connect
works. Especially for guest users and anonymous users, we havelogOutFirst: true
. This means that when connecting guest users and anonymous users, we will always logout first, and this means we calldisconnect()
which will stop the recovery handler. So the next time the user goes to background, the recovery handler will not be running, and so, it won't reconnect automatically. Here is the flow:So the problem is that when we logout a user first, and then connect it back again, we do not call again
start()
on the recovery handler. Changing this would require a bit of a refactoring so better to play safe and simple for now.All of this means that this could happen even for a regular user, not only guest users. If a regular user is logged in, then disconnects (without logging out) and then connects with a different user, and then going to background, it would happen the same issue, although this flow is quite rare and usually means a bad integration, since for different users, customers should always logout.
🧪 Manual Testing Notes
staysConnectedInBackground
☑️ Contributor Checklist