pushy / pushy-flutter

The official Pushy SDK for Flutter apps.
Apache License 2.0
21 stars 19 forks source link

Connect exception: (0) - java.net.UnknownHostException: mqtt-XXXXXX.pushy.io #26

Closed yixiaoyx closed 3 years ago

yixiaoyx commented 3 years ago

I'm experiencing an issue using Pushy Flutter SDK on Android that sometimes Pushy will encounter a connection exception and couldn't reconnect, and notifications sent after that will not be received. My phone is not in battery saving mode when this happened.

Here is what's in logcat: (the numbers and tokens are redacted)

2021-01-22 14:22:36.811 2859-2897/app.package.name D/Pushy: Connected successfully (sending keep alive every 300 seconds)
2021-01-22 14:22:37.113 2859-5277/app.package.name D/Pushy: Connection lost
2021-01-22 14:22:37.122 2859-2897/app.package.name D/Pushy: PushyJobService: Connecting...
2021-01-22 14:22:37.123 2859-2897/app.package.name D/Pushy: Broker: ssl://mqtt-XXXXXXX.pushy.io:443
2021-01-22 14:22:37.123 2859-2897/app.package.name D/Pushy: Device Token: XXXXXXX
2021-01-22 14:22:37.123 2859-2897/app.package.name D/Pushy: Device Auth Key: XXXXXXX... [truncated]
2021-01-22 14:22:37.143 2859-2897/app.package.name D/Pushy: Connect exception:  (0) - java.net.UnknownHostException: mqtt-XXXXXXX.pushy.io
2021-01-22 14:22:37.144 2859-2897/app.package.name D/Pushy: Reconnecting in 1000ms

After that last line there was no more logs printed. It looks like Pushy did not reconnect, because when I then send a notification the app didn't receive it, nothing was printed in logcat, and it's shown as pending delivery on the dashboard.

pushy commented 3 years ago

Hi @yixiaoyx, Thanks for reporting this issue. We'd be glad to assist.

Looking into the logs, it appears the device lost its Internet connection:

Connect exception:  (0) - java.net.UnknownHostException

An UnknownHostException occurs when the device cannot resolve a DNS query (due to lacking Internet connectivity) or due to Doze mode.

If you are sure that the device is connected to a healthy Internet connection when this occurs, please see this article on how to workaround Doze mode: How can I send notifications to Android devices in Doze / power saving mode?