We are getting intermittent 401 Unauthorized errors from Google's GCM service. In the past, it worked 100% of the time. The problem might coincide with our routers accepting IPv6 traffic, but the problem remains now even if we disable IPv6 on the adapter. It also doesn't work on a separate IPv4-only network. We also retry our requests using Google's recommended exponential back-off (http://developer.android.com/google/gcm/adv.html#retry), so the problem could have been developing over time and we might have not noticed.
All the production IPv4 and IPv6 addresses we've tested are listed in our project at: https://console.developers.google.com
Here is what our key looks like, we've got our entire publicly accessible subnet listed for testing, but I've tried with just single IP addresses as well.
Sometimes it works:
C:\Users\Administrator>curl --header "Authorization: key=REDACTED" --header Content-Type:"application/json" https://android.googl
eapis.com/gcm/send -d "{\"registration_ids\":[\"test\"],\"data\":{\"code\":123}
}" -k
{"multicast_id":REDACTED,"success":0,"failure":1,"canonical_ids":0,"r
esults":[{"error":"InvalidRegistration"}]}
But, sometimes we get this response:
C:\Users\Administrator>curl --header "Authorization: key=REDACTED" --header Content-Type:"application/json" https://android.googl
eapis.com/gcm/send -d "{\"registration_ids\":[\"test\"],\"data\":{\"code\":123}
}" -k
<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>
Minor Update (4/10/2014)
Changing the settings to "Any IP allowed" fixes the problem, but changing to any other IP address or addresses breaks it again.