googleapis / googleapis/google-api-java-client

Default connection pool is poorly configured in ApacheHttpTransport. Oauth2 library

Aperta
#1,060 3 commenti 20 reazioni 0 assegnatari Vedi su GitHub
priority: p4 type: feature request
Lingua principale
Java
Stelle
1.5k
Fork
772
Merge medio
1h 44m
PR unite (30g)
1

Descrizione

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)
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.