diff --git a/sdk/storage/azure-storage-common/CHANGELOG.md b/sdk/storage/azure-storage-common/CHANGELOG.md index d55297e33681a..1b8fc508fd557 100644 --- a/sdk/storage/azure-storage-common/CHANGELOG.md +++ b/sdk/storage/azure-storage-common/CHANGELOG.md @@ -7,6 +7,7 @@ ### Breaking Changes ### Bugs Fixed +- Fixed bug where RequestRetryOptions.tryTimeout adds delay to the client request in the synchronous http client flow. ### Other Changes diff --git a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/policy/RequestRetryPolicy.java b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/policy/RequestRetryPolicy.java index ca92c93ba71ec..79230e1ebf07d 100644 --- a/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/policy/RequestRetryPolicy.java +++ b/sdk/storage/azure-storage-common/src/main/java/com/azure/storage/common/policy/RequestRetryPolicy.java @@ -253,19 +253,17 @@ private HttpResponse attemptSync(final HttpPipelineCallContext context, HttpPipe * We want to send the request with a given timeout, but we don't want to kickoff that timeout-bound * operation until after the retry backoff delay, so we call delaySubscription. */ - HttpResponse response = next.clone().processSync(); + Mono httpResponseMono = Mono.fromCallable(() -> next.clone().processSync()); // Default try timeout is Integer.MAX_VALUE seconds, if it's that don't set a timeout as that's about 68 years // and would likely never complete. // TODO (alzimmer): Think about not adding this if it's over a certain length, like 1 year. if (this.requestRetryOptions.getTryTimeoutDuration().getSeconds() != Integer.MAX_VALUE) { - try { - Thread.sleep(this.requestRetryOptions.getTryTimeoutDuration().toMillis()); - } catch (InterruptedException ie) { - throw LOGGER.logExceptionAsError(new RuntimeException(ie)); - } + httpResponseMono = httpResponseMono.timeout(this.requestRetryOptions.getTryTimeoutDuration()); } + HttpResponse response = httpResponseMono.block(); + boolean newConsiderSecondary = considerSecondary; int statusCode = response.getStatusCode(); boolean retry = shouldStatusCodeBeRetried(statusCode, tryingPrimary); diff --git a/sdk/storage/azure-storage-common/src/test/java/com/azure/storage/common/policy/RequestRetryPolicyTest.java b/sdk/storage/azure-storage-common/src/test/java/com/azure/storage/common/policy/RequestRetryPolicyTest.java index 46d49882cd241..1d2197e2677c2 100644 --- a/sdk/storage/azure-storage-common/src/test/java/com/azure/storage/common/policy/RequestRetryPolicyTest.java +++ b/sdk/storage/azure-storage-common/src/test/java/com/azure/storage/common/policy/RequestRetryPolicyTest.java @@ -104,14 +104,14 @@ private void beforeSendingRequest(HttpRequest request) { @Override public HttpResponse sendSync(HttpRequest request, Context context) { - beforeSendingRequest(request); - return response; + return send(request).block(); } @Override public Mono send(HttpRequest request) { beforeSendingRequest(request); - return Mono.just(response); + return count < 3 + ? Mono.just(response).delaySubscription(Duration.ofSeconds(5)) : Mono.just(response); } }) .policies(new RequestRetryPolicy(retryTestOptions))