Ionic network plugin bug

Hi Guys, I’m having a problem with my ionic 4 app, I have the network plugin for which I listen to network changes, both onconnect and ondisconnect. The idea is to have a clear status of the network at any time but I have seen this doesn’t always work in the right way, specially when switching the way you are connected either by wifi or mobile data.

The behaviour I see is that sometimes when you switch the wifi off and you do have mobile data the ondisconnect is fired - which could make sense but for a very brief amount on time until the mobile data is set for which the onconnect event should fire and this is not always the case. When you are offline I show a message to the user - you can imagine how annoying it could be to see ‘you are offline’ and then ‘you are online’ just after this in less than a second (which I’m currently solving with a timeout that I clear if I get another event fired before some time elapses, anyhow…), but on some cases the onconnect is not even fired.

On my app I block all http calls when this happens and with the current behavior this is not accurate at all… You can imagine how bad it could be to an user to not been able to reach the server while they DO actually have a network connection… at the moment I’m forcing to call an http call just to listen to its response in order to ensure that the user is actually offline, so an http timeout need to happen before I can tell the user he’s offline which is not ideal since this take some more time and currently I can’t rely on this native plugin. Did anyone saw this behavior before or has any tip about it ?

So, finally got the problem.

My app has a login under which a token is fetched and this token may expire. What was happening what that when installing a new version the data was stored so the app showed the main dashboard and just after that a logout triggered due to a token expiration.

Because of this, for a small amount of time the main dashboard page loaded, and by doing so a subscription to network changes which I didn’t unsubscribed, after logging in again a new subscription was created, therefore each time a network changed occurred the event fired twice. Nothing to do with the plugin - realized I needed to review all my subscriptions and unsubscribe eventually to avoid this kind of behavior (besides avoiding memory leaks and a minor performance boost). My bad.-