jbagg / QtZeroConf

Qt wrapper class for ZeroConf libraries across various platforms.
Other
70 stars 51 forks source link

Android: Temporary resolution failures result in service removal #40

Open mzanetti opened 4 years ago

mzanetti commented 4 years ago

Using QtZeroconf on Android, I've noticed that resuming from suspend would often cause services to disappear even if they should not and it would take up to minutes for them to reappear. I've tracked it down to this code block which removes the service entry if resolving of a service fails:

https://github.com/jbagg/QtZeroConf/blob/master/avahicore.cpp#L206

The problem with this is that it seems to happen frequently when the app is in background, or the display is locked. This does not necessarily mean the other device disappeared. I understand that just removing this may cause situations where a remote service does not respond any more for real.

Not sure what the proper fix would be but I feel like the current situation might be to aggressively removing services, at least for my use case. Perhaps one option could be to pass the remove reason (eg. serviceUnregistered/resolveFailed). Or maybe not removing the service but just flagging the resolve failure in a property?

I suppose the same goes for avahiclient, but on systems with an actual avahi running presumably this happens way less often.

jbagg commented 4 years ago

What versions of Android have you tried?

mzanetti commented 4 years ago

Android 10 on Pixel 3.

jbagg commented 4 years ago

Can you print out the value of event when it is entering this code block?

jbagg commented 4 years ago

Looks like there is only 2 values in the enumeration so it must be AVAHI_RESOLVER_FAILURE.

jbagg commented 4 years ago

If you try and connect to your service as soon as you get the serviceRemoved signal, can you connect?

mzanetti commented 4 years ago

If you try and connect to your service as soon as you get the serviceRemoved signal, can you connect?

D nymea-app: Zeroconf: Setting connection offline: "Maveo" "nymeas://10.10.10.113:2223"
W nymea-app: *** socket state changed QUrl("nymeas://10.10.10.113:2223") QAbstractSocket::HostLookupState
W nymea-app: *** socket state changed QUrl("nymeas://10.10.10.113:2223") QAbstractSocket::ConnectingState
W nymea-app: *** socket state changed QUrl("nymeas://10.10.10.113:2223") QAbstractSocket::ConnectedState

Seems I can.