Repository navigation
Default connection pool is poorly configured in ApacheHttpTransport. Oauth2 library #1060
Description
As is, the default pool doesn't work well in a situation where the pool is infrequently used and causes NoHttpResponseExceptions.
This is because the pool defaults to an infinite keep alive time on the pooled connections when the server isn't providing a keep alive header. If they aren't used frequently, the connection on the Google server side will be closed. The connections aren't checked before re-use and you end up getting exception stacks like the one posted below.
These are totally avoidable by configuring the ConnectionKeepAliveStrategy on the pool OR providing a connection keep alive header value on the server responses. It seems like you should be able to provide a solid default keep alive configuration with knowledge of how long the server will actually keep connections open.
Stack trace below
Caused by: org.apache.http.NoHttpResponseException: www.googleapis.com:443 failed to respond
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:143)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:57)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:261)
at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:283)
at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:259)
at org.apache.http.impl.conn.AbstractClientConnAdapter.receiveResponseHeader(AbstractClientConnAdapter.java:232)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:272)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:124)
at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:686)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:488)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:884)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.google.api.client.http.apache.ApacheHttpRequest.execute(ApacheHttpRequest.java:67)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:981)
at com.google.api.client.googleapis.auth.oauth2.GooglePublicKeysManager.refresh(GooglePublicKeysManager.java:172)
at com.google.api.client.googleapis.auth.oauth2.GooglePublicKeysManager.getPublicKeys(GooglePublicKeysManager.java:141)
at com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier.verify(GoogleIdTokenVerifier.java:174)
at com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier.verify(GoogleIdTokenVerifier.java:192)
Activity
bit-twit commentedon Nov 10, 2017
I'm just posting this for other people that encounter this error and need a quick solution.
Example of custom HTTP client implementation that can be used with google api.
We use it to get rid of org.apache.http.NoHttpResponseException.
One mention: this is no optimized for high traffic - for high traffic Apache HC suggests to actually catch error and retry if you consider appropiate.
Link: Apache HTTP Client docs
kubukoz commentedon Feb 14, 2018
Just hit it, confirmed that it happens after a long time of not using the connection.
chenjianjx commentedon Mar 2, 2019
When will this be fixed in this open source project? Any ETA ?