Repository navigation
Closed
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
Environment details
The same environment as in #795.
Steps to reproduce
.setConnectTimeout(4000)- Call
https://example.com:81. It always times out after 30 seconds (on my machine) with 1.31.0. See the example code below.example.comis reserved by the DNS standard, so this will always trigger timeout.
Note that I haven't tested read timeout.
Code example
- 1.31.0: output proves that it times out after 30 seconds.
public class Main {
public static void main(String[] args) throws IOException {
GenericUrl url = new GenericUrl("https://example.com:81");
HttpRequest req = new ApacheHttpTransport().createRequestFactory().buildGetRequest(url).setConnectTimeout(4000);
long started = System.nanoTime();
try {
req.execute();
} finally {
System.out.println("elapsed (s): " + (System.nanoTime() - started) / 1000000000L);
}
}
}elapsed (s): 30
Exception in thread "main" org.apache.http.conn.HttpHostConnectException: Connect to example.com:81 [example.com/93.184.216.34, example.com/2606:2800:220:1:248:1893:25c8:1946] failed: Connection timed out (Connection timed out)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:156)
- 1.27.0: connect timeout is honored.
elapsed (s): 4
Exception in thread "main" java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
Any additional information below
I noticed another behavioral change from 1.27.0 to 1.31.0 that 1.31.0 throws HttpHostConnectException while 1.27.0 throws java.net.SocketTimeoutException, but I think it is a bug in the Apache library in DefaultHttpClientConnectionOperator. I will file a bug against them.
} catch (final ConnectException ex) {
if (last) {
final String msg = ex.getMessage();
throw "Connection timed out".equals(msg)
? new ConnectTimeoutException(ex, host, addresses)
: new HttpHostConnectException(ex, host, addresses);
}Metadata
Metadata
Assignees
Labels
priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
Activity
chanseokoh commentedon Aug 22, 2019
I have tested using Apache HttpClient directly (4.5.9 and 4.5.6) and the connect timeout works great. That makes me believe Google HTTP Client is at fault here.
Filed HTTPCLIENT-2013.
chanseokoh commentedon Aug 22, 2019
Also note that the Google HTTP Client claims that the default timeout is 20 seconds. So, the 30 second timeout is coming from somewhere else.
chanseokoh commentedon Aug 22, 2019
https://stackoverflow.com/a/37996423/1701388
If I understand the SO link correctly,
setConnectionRequestTimeout()is the deadline to wait until a connection manager returns a usable connection. For example, if all the established connections in a pool are sold out and busy, this will make the caller wait for at most the given timeout for the pool manager to return a connection. That said, I think we should also do.setConnectTimeout()?