Apollo iOS - websocket keeps reconnecting and failing to connect, resulting loop

Hi guys. I am currently working on my project where im having problem with websocket.
When user change profile in the settings, I am cancelling active subscriptions on Cancellable value that holds that subscription(as documentation says https://www.apollographql.com/docs/ios/subscriptions/), and in the meantime I am making that same subscriptions, but with the different ID. Configuration is done according to documentation, using SplitNetworkTransport. In most cases, when you trigger cancelling and creating new subscriptions, apollo is trying to connect websocket, but it ends up in the loop: websocket is disconnected ( most of the time without error message, sometimes with "Invalid message received", code: 4400).

When Im not cancelling subscriptions(Cancellable.cancel()), everything works fine.
Project is using graphql-transport-ws protocol.
Any help would be awesome, because im stuck on this problem for a very long time. :smiley:

Hi @Tom123, thanks for letting us know and sorry that you’ve been stuck with this for a while. Are you able to reproduce this problem in a standalone sample project? It would be helpful for debugging - thanks.

The 4400 error code would indicate an unexpected message sequence. At a guess I’m thinking the socket is not being closed correctly.

@Tom123 I recently made a fix for an issue that I think is directly related to what you’re experiencing here - graphql-ws Protocol Support · Issue #1622 · apollographql/apollo-ios · GitHub. It hasn’t gone out in a published release yet but if you try the latest in main it will include the change.