SocketTimeoutException using URLFetch to a service that sends channel messages

510 Views Asked by At

We have two AppEngine (Java) apps. One of them uses URLFetch to the other to create an appointment. In the receiver, we've added a feature where we use the Channel API to see if there are any open channels and let them know about the new data.

The URLFetch call is failing with a SocketTimeoutException. All the code in the receiver is executed (including all open channels being notified) but the calling app still gets a SocketTimeoutException. When I comment out the channel notification line, no error.

This happens only in the deployed app, not in dev mode. Also, the call doesn't come close to reaching the 60-second (or even the old 10-second) timeout allowed by URLFetch.

1

There are 1 best solutions below

0
On

The default deadline for urlfetch is 5s, so if your application take more than 5s to load and execute the handler it will return a SocketTimeoutException.

As described in the documentation, you can set a longer deadline for your urlfetch call using setConnectTimeout or setReadTimeout

In addition, it is a good idea to move the api call that can be deferred (i.e not necessary to build the http response) to a task queue:

  • the deadline for task queue request is longer (10 minutes, instead of 60s)
  • the task will be retried if failing
  • urlfetch timeout is longer too (10 minutes)