Skip to content
This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Commit 86c68b3

Browse files
authored
fix: REGAPIC fix socket timeout for wait calls (#1476)
wait() LRO calls may take 2+ minutes, while default read timeout was 20sec.
1 parent 8e86f96 commit 86c68b3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
import java.util.List;
5555
import java.util.Map;
5656
import java.util.Map.Entry;
57+
import org.threeten.bp.Duration;
58+
import org.threeten.bp.Instant;
5759

5860
/** A runnable object that creates and executes an HTTP request. */
5961
@AutoValue
@@ -115,6 +117,16 @@ HttpRequest createHttpRequest() throws IOException {
115117

116118
HttpRequest httpRequest = buildRequest(requestFactory, url, jsonHttpContent);
117119

120+
Instant deadline = getHttpJsonCallOptions().getDeadline();
121+
if (deadline != null) {
122+
long readTimeout = Duration.between(Instant.now(), deadline).toMillis();
123+
if (httpRequest.getReadTimeout() > 0
124+
&& httpRequest.getReadTimeout() < readTimeout
125+
&& readTimeout < Integer.MAX_VALUE) {
126+
httpRequest.setReadTimeout((int) readTimeout);
127+
}
128+
}
129+
118130
for (HttpJsonHeaderEnhancer enhancer : getHeaderEnhancers()) {
119131
enhancer.enhance(httpRequest.getHeaders());
120132
}

0 commit comments

Comments
 (0)