The server i'm hitting is responding at 5.5 seconds regularly but I'm getting a SocketTimeoutException at 5 seconds even. Is there a way to increase this value? Will upgrading to a paid tier allow me this ability?
2 Answers
See https://developers.google.com/appengine/docs/java/urlfetch/#Fetching_URLs_with_java_net
In particular
You can set a deadline for a request, the most amount of time the service will wait for a response. By default, the deadline for a fetch is 5 seconds. The maximum deadline is 60 seconds for HTTP requests and 10 minutes for task queue and cron job requests. When using the URLConnection interface, the service uses the connection timeout (setConnectTimeout()) plus the read timeout (setReadTimeout()) as the deadline.

- 6,592
- 1
- 18
- 26
You haven't tagged your question with any language, so I'll try to cover the ones that I know.
I haven't tested any of these in production, only on development.
Python
Seems to support the setdefaulttimeout method. You can pass in number of seconds as a float
or int
:
import socket
socket.setdefaulttimeout(10)
# create socket connections as usual…
Java
The socket documentation claims that it natively supports java.net.Socket. According to this answer, you can specify the timeout in milliseconds, like this (10 seconds):
Socket socket = new Socket();
socket.connect(new InetSocketAddress(ipAddress, port), 10000);
Go
Using socket.DialTimeout instead of socket.Dial you can specify the timeout as a time.Duration object (i.e. nanoseconds).
import (
// …
"appengine/socket"
)
func handler(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
conn, err := socket.DialTimeout(c, "tcp", "myhost.com:1234", 10*time.Second)
// …
}
Note that the timeout may include name resolution, if you connect to a hostname rather than a bare IP. There might also be an upper limit that is not language-specific, but it isn't documented.