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

IOWebSocketChannel behaviour impaired after Android app sleep #276

Open
gbfarah opened this issue Jul 14, 2023 · 3 comments
Open

IOWebSocketChannel behaviour impaired after Android app sleep #276

gbfarah opened this issue Jul 14, 2023 · 3 comments

Comments

@gbfarah
Copy link

gbfarah commented Jul 14, 2023

We are noticing this unusual behaviour that may need some feedback. We setup a channel as below

`
var channel = IOWebSocketChannel.connect(Uri.parse(url), connectTimeout: const Duration(seconds: 3));
_subscription = channel.stream.listen(onMessage, onDone: onClosed, onError: onError);

`

When app is in the foreground and alive, any changes in internet connection correctly and properly fire OnDone events appropriately allowing for a swift reconnection if the network has changed.

The issue we observe is as follows

  1. Bring app to foreground with WIFI and 5G on
  2. Put app to background and wait for Android to put in Doze
  3. Disconnect WIFI whilst app is asleep
  4. Bring app back up again

We notice that no onDone or onError messages are fired (presumably because the socket was cleared whilst app is asleep). This is a little troublesome but I can understand it...

If we use another mechanism to clean up the stuck socket (as we missed events) , we clean up the socket and reconnect a new one. Although reconnection is successful , from then on web_socket_dart no longer reports OnDone or OnError events . This is even if the app was in the foreground and running from then on.

I think perhaps maybe the fact that the library missed events during the sleep period has resulted in callback handlers being corrupted.

Anyone else have this issue ?

@panmin
Copy link

panmin commented Dec 23, 2023

me too

@gbfarah
Copy link
Author

gbfarah commented Dec 24, 2023

@panmin . Unfortunately as issue was not resolved we had to implement an app layer socket check/keep alive. Flutter events were to consistently being not fired. This solution is inefficient but needed for time being

@xalgia
Copy link

xalgia commented Apr 23, 2024

I am facing a similar issue. It also happens when the websocket is opened and the network is switched, or in the case of flutter desktop when a computer running a flutter app wakes up from sleep.

This is mission critical for my org so if any developer/maintainer of this project can point me in the right direction, I will be happy to attempt to fix this myself

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