Skip to content
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

WebSocket Fails To Reconnect When Internet Is Disconnected Then Restored #3498

Open
oolabib opened this issue Jan 9, 2025 · 4 comments
Open
Labels
bug Generally incorrect behavior needs investigation

Comments

@oolabib
Copy link

oolabib commented Jan 9, 2025

Summary

In a legacy project I'm stuck with version 0.53.0 of Apollo-iOS.

I noticed once thing, the subscription is not restored when it's disconnected initially. I even tried manually disconnecting and reconnecting but in vain.

Here's

nw_connection_get_connected_socket_block_invoke [C24] Client called 
nw_connection_get_connected_socket on unconnected nw_connection
TCP Conn 0x60000332e080 Failed : error 0:50 [50]
"websocket is disconnected: Error Domain=NSPOSIXErrorDomain Code=50 \"Network is down\" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}"

Version

0.53.0

Steps to reproduce the behavior

I disconnected the device from internet, landed on a screen where a subscription is fired. The subscription failed with these errors.

nw_connection_get_connected_socket_block_invoke [C24] Client called 
nw_connection_get_connected_socket on unconnected nw_connection
TCP Conn 0x60000332e080 Failed : error 0:50 [50]
"websocket is disconnected: Error Domain=NSPOSIXErrorDomain Code=50 \"Network is down\" UserInfo={_kCFStreamErrorCodeKey=50, _kCFStreamErrorDomainKey=1}"

I reconnected the internet, made another mutation from same screen, and it's successful, however, the subscription errors are still being logged at the reconnection interval rate.

I noticed two things while debugging..

  1. Even if I set reconnect = false and try to manually deallocate the subscription by setting to nil or call .cancel and reassign it again, the same errors are getting logged.

  2. I was debugging the library source code, and added few breakpoints here and there, and surprisingly sometimes the subscription was restored. This happened few times but I couldn't infer the exact steps to reproduced.

@oolabib oolabib added bug Generally incorrect behavior needs investigation labels Jan 9, 2025
@BobaFetters
Copy link
Member

@oolabib sounds like maybe some internal state is getting messed up, have you tried creating a completely new web socket instance when network connectivity is restored to see if that gets around the issue?

@oolabib
Copy link
Author

oolabib commented Jan 12, 2025

@BobaFetters I'm using a singleton instance of the client in the app with the same web socket, shouldn't I?

@BobaFetters
Copy link
Member

@oolabib No that shouldn't be an issue, was just suggesting trying to clear your existing web socket instance and create a new one to test if that resolves your issue since it could be that there is some internal state in the web socket maybe not being reset correctly potentially causing the issue you are seeing. Imagine you could add a way to reset the internal state of your singleton instance to allow you to do so.

@oolabib
Copy link
Author

oolabib commented Jan 12, 2025

Hmmm, I will try it out and let you know 👌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior needs investigation
Projects
None yet
Development

No branches or pull requests

2 participants