awslabs / aws-mobile-appsync-sdk-js

JavaScript library files for Offline, Sync, Sigv4. includes support for React Native
Apache License 2.0
920 stars 266 forks source link

Socket state detection #572

Open michaeltreyvaud opened 4 years ago

michaeltreyvaud commented 4 years ago

Do you want to request a feature or report a bug? Feature

What is the current behavior? Unable to determine socket state and unable to re-init socket handshake.

What is the expected behavior? I expect to be able to detect when the socket enters a closing/closed state, and be able to re-connect.

Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions? Currently using v3.0.3, we have never been able to detect socket state transitions.

Hello all! Right now, when a socket hangs, or the clients network drops we are having issues re-connecting subscriptions correctly.

I have taken a naive approach on the client by attaching event listeners on the navigation.onLine state, when we detect a transition from offline to online, I re-init the app sync client which essentially re-boots all our app sync subscriptions.

However, this does not solve issues when the socket enters a closing/closed state without a drop in the network (usually occurs 1-4 hours of lying idle).

Is there a way to detect socket hangups at all using the appsync client? I also notice that subscriptions that have lost their connection over the socket do not throw accessible errors that I can catch and use.

I have also tried passing in our own apollo ws link, but I was unable to get the client to understand the auth handshake that the appsync client is using under the hood.

Any help or guidance would be greatly appreciated.

Mike

brayoh commented 2 years ago

Any progress on this?