GetStream / stream-chat-swift

💬 iOS Chat SDK in Swift - Build your own app chat experience for iOS using the official Stream Chat API
https://getstream.io/chat/sdk/ios/
Other
849 stars 204 forks source link

WebSocket Does Not Reconnect When App Resumes from Background (Guest User) #3338

Open masarusanjp opened 1 month ago

masarusanjp commented 1 month ago

What did you do?

I launched the app, waited for a few minutes, and then resumed it.

What did you expect to happen?

I expected the WebSocket to reconnect when the app resumes from the background.

What happened instead?

The WebSocket does not reconnect when the app resumes from the background.

GetStream Environment

GetStream Chat version: 4.60.0 GetStream Chat frameworks: StreamChat, StreamChatUI iOS version: iOS17.4 Swift version: 5.9 Xcode version: 15.3 Device: Simulator iPhone 15 Pro

Additional context

Reproduce Step

Screencast

https://drive.google.com/file/d/1-parw6tuS02VBZW7cG3__1Pb4e3ciogL/view?usp=sharing (Here is a link to GoogleDrive due to its large size)

Additional Information

I discovered that the connectGuestUser function calls logOut first. As a result, ConnectionRecoveryHandler.stop is invoked, causing the monitoring of appDidBecomeActive and appDidEnterBackground to stop. This leads to the issue where "the WebSocket does not reconnect when the app resumes from the background.

https://github.com/GetStream/stream-chat-swift/pull/3303/files#diff-5aa17a3514ab85c33231ca8983e4c32096742c79d97924fe31e71ebb0ac7d540R385

This issue reliably reproduces with a guest user, but it is likely to occur under any condition where logOutFirst is true.

nuno-vieira commented 1 month ago

Hi @masarusanjp, thanks for spotting this issue!

The actual issue is that when reconnecting, logOut should not be happening, so the logic should be changed here. Stopping the recovery handler on logout is something that we want, but it caused this unwanted side effect due to the fact that logOutFirst in guest user is not properly implemented it seems.

We will pan this fix, and we will let you know once we start working on it. At the moment we do not have an ETA on when this will be fixed.

Best, Nuno

98prabowo commented 1 month ago

Hi @nuno-vieira, does this only affect guest user? or all user?

nuno-vieira commented 1 month ago

Hi @nuno-vieira, does this only affect guest user? or all user?

Hello! Only guest and anonymous user yes.