pusher / pusher-websocket-swift

Pusher Channels websocket library for Swift
https://pusher.com/channels
MIT License
272 stars 164 forks source link

Pusher not consistently reconnecting when app comes back into foreground #420

Open sarya opened 9 months ago

sarya commented 9 months ago

Steps to reproduce

Open the app, put the app in the background (e.g. switch to another app or lock the sreen), return to the app. Sometimes Pusher will reconnect in this scenario, but eventually the app will come into the foreground and Pusher will not reconnect. The user will have to force quit/relaunch the app to restore the connection.

Expected behavior

Pusher reconnects/resubscribes to channels every time the app is moved from background to foreground.

Actual behavior

The app is brought back into the foreground but Pusher stays in the "disconnected" state (according to the debug console).

I have attempted to play around with the maxReconnectGapInSeconds and reconnectAttemptsMax settings on the PusherConnection object but am still seeing the same outcome.

...

sarya commented 9 months ago

Looks similar to this Java client issue from a few years back: https://github.com/pusher/pusher-websocket-java/issues/197

dgarciasquare1 commented 7 months ago

Any solution to this problem ??

benw-pusher commented 7 months ago

We have made some changes that may help in this area, I will look into getting a new release made so you can upgrade.

benw-pusher commented 7 months ago

We just released version 10.1.5 - could you upgrade and let me know if this helps resolve the issue? https://github.com/pusher/pusher-websocket-swift/releases/tag/10.1.5

spasbilyarski commented 6 months ago

@benw-pusher I updated to 10.1.5 but started seeing a handshake problem:

[PUSHER DEBUG] websocketDidReceiveMessage {"event":"pusher:error","data":{"code":4201,"message":"Pong reply not received"}}
<PusherSwift.PusherError: 0x600000c1fc60>
nw_read_request_report [C5] Receive failed with error "Socket is not connected"
[PUSHER DEBUG] Websocket received error. Error: POSIXErrorCode(rawValue: 57): Socket is not connected
[PUSHER DEBUG] Websocket received error. Error: POSIXErrorCode(rawValue: 57): Socket is not connected
[PUSHER DEBUG] Websocket is disconnected but no error received Close code: Optional(1001). Reason: The websocket disconnected unexpectedly.
[PUSHER DEBUG] Websocket is disconnected but no error received Close code: Optional(1001). Reason: The websocket disconnected unexpectedly.

Just rolled back to 10.1.4 and will get back to you if I see this problem persisting in the older version, making this comment unrelated.

EDIT: The problem is 10.1.5 specific. EDIT2: This issue is happening after ~2 hours of receiving messages in foreground.

DelphineGarcia commented 1 month ago

We are also facing some reconnection issues after a long time in background. Any news on this? Using 10.1.4 can't be a solution for us since there are even more reconnection issue. Thanks

Capture d’écran 2024-07-31 à 15 47 23