googleapis / googleapis/google-api-java-client
Drive: Batch request timeout docu improvement
- Langage dominant
- Java
- Étoiles
- 1.5k
- Forks
- 772
- Merge moyen
- 1 h 44 min
- PR mergées (30 j)
- 1
Description
#### Environment details
1. Specify the API at the beginning of the title. For example, "BigQuery: ...").
General, Core, and Other are also allowed as types
2. OS type and version: Linux tux 6.12.39-1-MANJARO
3. Java version: openjdk 21.0.8 2025-07-15
4. version(s): google-api-services-drive v3-rev20250723-2.0.0
#### Steps to reproduce
1. create batch request with ~20 Drive Permission creating request
2. sometimes get `java.net.SocketTimeoutException : Read timed out`
#### Code example
```java
BatchRequest batch = service.batch();
// write instead ↓
BatchRequest batch = service.batch(new HttpRequestInitializer() {
@Override
public void initialize(HttpRequest request) throws IOException {
requestInitializer.initialize(request);
request.setConnectTimeout(3 * 60_000);
request.setReadTimeout(3 * 60_000);
}
});
```
#### Stack trace
```
java.net.SocketTimeoutException: Read timed out
at java.base/sun.nio.ch.NioSocketImpl.timedRead(NioSocketImpl.java:278)
at java.base/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:304)
at java.base/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:346)
at java.base/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:796)
at java.base/java.net.Socket$SocketInputStream.read(Socket.java:1099)
at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:489)
at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:483)
at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:70)
at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1461)
at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:1066)
at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:291)
at java.base/java.io.BufferedInputStream.read1(BufferedInputStream.java:347)
at java.base/java.io.BufferedInputStream.implRead(BufferedInputStream.java:420)
at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:399)
at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:827)
at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:759)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1706)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1615)
at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:531)
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:307)
at com.google.api.client.http.javanet.NetHttpResponse.(NetHttpResponse.java:36)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:152)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:84)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1012)
at com.google.api.client.googleapis.batch.BatchRequest.execute(BatchRequest.java:257)
```
#### External references such as API reference guides
- https://developers.google.com/api-client-library/java/google-api-java-client/errors
- https://stackoverflow.com/questions/31312692/change-read-timeout-for-a-batch-http-request-on-using-google-api-client-library?rq=4
similar problem
- https://stackoverflow.com/questions/70358867/gcp-java-sdk-throwing-socket-connection-timeout-after-20seconds?noredirect=1&lq=1
#### Any additional information below
When searching for the error you find following docu https://developers.google.com/api-client-library/java/google-api-java-client/errors . Sadly it does not mention that you need to set the `HttpRequestInitializer` timeout for batch requests separately.
The default timeout seems very low (20s), so increasing it for batch requests is almost a must.
It would save a lot of time if either the default would be higher, but it would suffice if one could find the solution when searching for the error/exception.
As you can see, the stackoverflow post is from 2015, so nothing new.
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.