Problems with AppEngine and GCM: IOException: Could not fetch URL: https://android.googleapis.com/gcm/send

890 views
Skip to first unread message

hodenk...@gmail.com

unread,
Jul 8, 2013, 2:29:26 PM7/8/13
to google-a...@googlegroups.com
Hi,
I am using GCM in combination with Google AppEngine.
Our service sends more then 10.000 messages every day through GCM. Almost every message is successfully delivered to the receiver.

But about every day there are one or more messages which could not be delivered according to the following stack trace:

Uncaught exception from servlet
java
.io.IOException: Could not fetch URL: https://android.googleapis.com/gcm/send
        at com
.google.appengine.api.urlfetch.URLFetchServiceImpl.convertApplicationException(URLFetchServiceImpl.java:137)
        at com
.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:43)
        at com
.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.fetchResponse(URLFetchServiceStreamHandler.java:417)
        at com
.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.getInputStream(URLFetchServiceStreamHandler.java:296)
        at com
.google.apphosting.utils.security.urlfetch.URLFetchServiceStreamHandler$Connection.getResponseCode(URLFetchServiceStreamHandler.java:149)
        at com
.google.android.gcm.server.Sender.sendNoRetry(Sender.java:362)
        at com
.google.android.gcm.server.Sender.send(Sender.java:261)
        at de
.alamos.firemergency.apager.gcm.ApagerServlet.sendDataToAndroid(ApagerServlet.java:282)
        at de
.alamos.firemergency.apager.gcm.ApagerServlet.doPost(ApagerServlet.java:162)
       
...

The exception occurs at following position:
MulticastResult results = sender.send(message, tokens, 5);

Does anyone has some ideas what the resason of this problem could be?

Thanks for your help and greetings from Germany!
Simon

Vinny P

unread,
Jul 9, 2013, 1:08:48 AM7/9/13
to google-a...@googlegroups.com
On Mon, Jul 8, 2013 at 1:29 PM, <hodenk...@gmail.com> wrote:
Our service sends more then 10.000 messages every day through GCM.
But about every day there are one or more messages which could not be delivered according to the following stack trace:
Uncaught exception from servlet
java
.io.IOException: Could not fetch URL: https://android.googleapis.com/gcm/send

The exception occurs at following position:
MulticastResult results = sender.send(message, tokens, 5);

Does anyone has some ideas what the resason of this problem could be?

 
 Just to be clear, you're saying that your application sends 10,000 urlfetches to the GCM API endpoint (each one is a single message), and that every day "one or more" urlfetches fail?
 
Sounds about right. Some quick napkin math: (1 urlfetch failure / 10,000 urlfetch uses) * (100 percent) = 0.01% urlfetch failure rate (check my math, I'm about to go to bed at the time of writing this!).
 
URLFetch occasionally fails. It's just a fact of life on App Engine. The best thing for you to do is to catch the exception and retry the urlfetch. Better yet, put your urlfetch code within a task and queue up a task when you need to send a GCM message, the task queue service will automatically retry the task if it fails.
 
P.S.
 
I notice you said you were from Germany. Is your GAE application hosted in a US datacenter or an European datacenter ( https://groups.google.com/forum/#!topic/google-appengine/Oon8Ds3dlO4 )? Assuming that the GCM API is hosted out of a different region than your application, you may be experiencing higher urlfetch failure simply due to your location.
 
 
-----------------
-Vinny P
Technology & Media Advisor
Chicago, IL

App Engine Code Samples: http://www.learntogoogleit.com

 

hodenk...@gmail.com

unread,
Aug 15, 2013, 1:31:25 PM8/15/13
to google-a...@googlegroups.com
Thanks for the information.
Your solution with the queue sounds good. I think I will try this one.
Reply all
Reply to author
Forward
0 new messages