I had recently encountered delayed push notifications on my Android phone whenever the phone was logged onto my home WiFi network. There were no delays observed when the phone is logged onto the 3G or LTE mobile network or other WiFi networks. I decided to investigate.
Before diving into the problem, I found out how Google push notifications actually work on Android.
Brief Introduction to Google Push Notifications
In a nutshell, Google’s push notifications service work by making a connection on TCP port 5228 between the phone and Google servers.
Normally, TCP connections will be forced closed after an idle timeout. To prevent the connection from timing out, Android sends a periodic heartbeat every 15 minutes if you are on WiFi and every 28 minutes if you are on a mobile data connection.
So if the TCP connection is terminated by a network element (e.g. the WiFi router in this case) due to a TCP timeout, any new push notifications from Google servers will not be sent to the Android device. The push notifications will only be received when the mobile phone re-establishes the connection by sending a heartbeat to the Google push notification servers.
Fix on WiFi Router
To fix the problem, we will have to make sure that the TCP timeout on the WiFi router is more than 15 minutes.
I had initially tuned the TCP parameters on my WiFi router to improve the performance of P2P applications. One of the parameters that I modified was the TCP timeout parameter – I had changed it to 10 minutes from the default setting of 20 minutes (1200 seconds). I reverted the changes and reset the timeout to 20 minutes (or 1200 seconds).
Similarly, on your router, look for a “TCP Timeout” or similar setting and set it 20 minutes (with a buffer of 5 minutes in addition to the 15 minute heartbeat interval).
After the changes were made on my WiFi router, I did not experience any further delay on push notifications on my Android phone.
Alternative Fix on Android Mobile
If you are unable to modify the settings on your WiFi router for whatever reason, or if you suspect that it’s not the WiFi router issue, then there’s another alternative – reduce the heartbeat timer on your Android mobile.
To do that, install the Push Notifications Fixer app on your mobile. This app allows you to reduce the heartbeat interval to a low value (recommended value of 5 minutes) thereby increasing the chances of keeping the connection alive.