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 transport could be killed while javascript is asleep. #1312

Open
vyredo opened this issue Jan 8, 2023 · 3 comments
Open

websocket transport could be killed while javascript is asleep. #1312

vyredo opened this issue Jan 8, 2023 · 3 comments

Comments

@vyredo
Copy link

vyredo commented Jan 8, 2023

Hi thanks for the great work.
I encountered an issue with grpc-web when we used websocket as the transport layer.
The problem is if user is on mobile device and put the app to background for 10 minutes more or so.
When user active the tab again, the websocket already dead and since it's killed while Javascript is asleep.
I believe the 'onTransportEnd' method don't run.
I have a callback to reconnect websocket in when end is triggered. in this case the callback didn't run.

Is there anyway to get the status of websocket from the current implementation of grpc-web?
The problem is quite common and easy to solve by exposing websockets, or just a method to get the status of websockets.
For example:

  document.addEventListener("visibilitychange", () => {
         if(document.visibility === 'visible') {
               // get the status of each websocket connection and reconnect if it dies
         }
  })
@ban4e
Copy link

ban4e commented Jan 9, 2023

I faced the same problem. In addition to the end event, you can subscribe to the status event:

stream.on('status', function(status) {
  console.log(status.code);
  console.log(status.details);
  console.log(status.metadata);
});

In my case, when PC enters sleep mode, a status change is triggered with { code: 2, details: 'Http response at 400 or 500 level', ... }

I found the status table here.

Hope this helps you :)

@vyredo
Copy link
Author

vyredo commented Jan 9, 2023

I think it's different .
when PC enter a sleep mode, the websocket is killed before javascript is asleep.

For mobile device when user put app to background, the javascript is a sleep but websocket is still connected for some time and then it will be killed after few minutes while javascript is asleep.

@maja42
Copy link

maja42 commented Sep 19, 2023

Maybe this also relates to #1363, where no end-event is sent if the network changes. Though I'm not sure, as it doesn't use websockets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants