Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SocketTimeoutException at 5 seconds - Any way to increase?

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?

like image 451
tupakapoor Avatar asked Jun 27 '14 15:06

tupakapoor


People also ask

How do you increase Java net SocketTimeoutException read timed out?

A possible solution for this problem within the Tomcat web application is to modify the CONTEXT. XML file, and modify the CONNECTOR definition that governs the workstation browser connectivity to the Tomcat server. Specifically, modify the connectionTimeout value. Increase this value to suppress the error condition.

How do I resolve SocketTimeoutException?

Using try/catch/finally If you are a developer, so you can surround the socket connection part of your code in a try/catch/finally and handle the error in the catch. You might try connecting a second time, or try connecting to another possible socket, or simply exit the program cleanly.

Why does Java net SocketTimeoutException read timed out?

SocketTimeoutException: Read timed out. This error is typically caused by a maximum concurrent connections limit on the SFTP server itself (either total concurrent connections or concurrent connections from a specific IP).

What is a good socket timeout?

Best Answer. Given that on Policy server the default idle timeout for socket is 10min, I think 10 min is good vlaue for it.

What is sockettimeoutexception in Java?

In this example we are going to talk about java.net.SocketTimeoutException. This exception is a subclass of java.io.IOException, so it is a checked exception. From the javadoc we read that this exception :” Signals that a timeout has occurred on a socket read or accept”.

What does sockettimeout mean?

i understand what socketTimeout means, I am not getting read time out but connect time out, which means client fails to setup tcp connection with the server.Meaning server just disregards the clients attempt to connect it, as either its not available or too busy doing something else on that port. I know my server is reachable and up and running.

What causes a socket timeout in Java?

Signals that a timeout has occurred on a socket read or accept." To answer the question of what causes this, that would be your answer. Java was attempting to connect to a socket and it failed to connect before timing out. As for how to solve this, that depends on your use case.

Why does the HTTP socket time out before it is read?

In such cases, the HTTP socket might time out before the Web service engine completely reads the SOAP request. In the majority of cases, a sudden increase in overall network activity causes this problem.


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.

like image 112
Chris Lear Avatar answered Sep 29 '22 08:09

Chris Lear


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.

like image 41
Attila O. Avatar answered Sep 29 '22 08:09

Attila O.