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

Commit

Permalink
fix: REGAPIC fix socket timeout for wait calls (#1476)
Browse files Browse the repository at this point in the history
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 86c68b3
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
Expand Down

0 comments on commit 86c68b3

Please sign in to comment.