Skip to content
Permalink
Browse files
fix: REGAPIC fix socket timeout for wait calls (#1476)
wait() LRO calls may take 2+ minutes, while default read timeout was 20sec.
  • Loading branch information
vam-google committed Sep 8, 2021
1 parent 8e86f96 commit 86c68b3ffd241f6932516d0e7b5d9ae5714b89e0
Showing with 12 additions and 0 deletions.
  1. +12 −0 gax-httpjson/src/main/java/com/google/api/gax/httpjson/HttpRequestRunnable.java
@@ -54,6 +54,8 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.threeten.bp.Duration;
import org.threeten.bp.Instant;

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

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

Instant deadline = getHttpJsonCallOptions().getDeadline();
if (deadline != null) {
long readTimeout = Duration.between(Instant.now(), deadline).toMillis();
if (httpRequest.getReadTimeout() > 0
&& httpRequest.getReadTimeout() < readTimeout
&& readTimeout < Integer.MAX_VALUE) {
httpRequest.setReadTimeout((int) readTimeout);
}
}

for (HttpJsonHeaderEnhancer enhancer : getHeaderEnhancers()) {
enhancer.enhance(httpRequest.getHeaders());
}

0 comments on commit 86c68b3

Please sign in to comment.