Skip to content
This repository was archived by the owner on Jun 15, 2026. It is now read-only.

Commit ef64603

Browse files
authored
Proper fix for lro timeout (#162)
1 parent 19762a8 commit ef64603

2 files changed

Lines changed: 16 additions & 12 deletions

File tree

azure-client-runtime/src/main/java/com/microsoft/azure/AzureClient.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public final class AzureClient extends AzureServiceClient {
3434
private static final String LOGGING_HEADER = "x-ms-logging-context";
3535

3636
/**
37-
* The interval time between two long running operation polls. Default is
38-
* used if null.
37+
* The interval time between two long running operation polls. Default is 30 seconds.
3938
*/
40-
private Integer longRunningOperationRetryTimeout;
39+
private int longRunningOperationRetryTimeout = -1;
40+
4141
/**
4242
* The executor for asynchronous requests.
4343
*/
@@ -63,16 +63,20 @@ public AzureClient(AzureServiceClient serviceClient) {
6363
*
6464
* @return the time in seconds.
6565
*/
66-
public Integer getLongRunningOperationRetryTimeout() {
66+
public Integer longRunningOperationRetryTimeout() {
6767
return longRunningOperationRetryTimeout;
6868
}
6969

7070
/**
71-
* Sets the interval time between two long running operation polls.
71+
* Sets the interval time between two long running operation polls. Default is 30 seconds.
72+
* Set to any negative value to let AzureClient ignore this setting.
7273
*
73-
* @param longRunningOperationRetryTimeout the time in seconds.
74+
* @param longRunningOperationRetryTimeout the time in seconds. Set to any negative value to let AzureClient ignore this setting.
7475
*/
75-
public void withLongRunningOperationRetryTimeout(Integer longRunningOperationRetryTimeout) {
76+
public void setLongRunningOperationRetryTimeout(int longRunningOperationRetryTimeout) {
77+
if (longRunningOperationRetryTimeout < 0) {
78+
throw new IllegalArgumentException("Invalid timeout for long running operations : " + longRunningOperationRetryTimeout);
79+
}
7680
this.longRunningOperationRetryTimeout = longRunningOperationRetryTimeout;
7781
}
7882

@@ -137,7 +141,7 @@ public Observable<ServiceResponse<T>> call(Response<ResponseBody> response) {
137141
}
138142

139143
try {
140-
final PollingState<T> pollingState = new PollingState<>(response, getLongRunningOperationRetryTimeout(), resourceType, restClient().serializerAdapter());
144+
final PollingState<T> pollingState = new PollingState<>(response, longRunningOperationRetryTimeout(), resourceType, restClient().serializerAdapter());
141145
final String url = response.raw().request().url().toString();
142146

143147
// Task runner will take it from here
@@ -294,7 +298,7 @@ public Observable<ServiceResponse<T>> call(Response<ResponseBody> response) {
294298
}
295299

296300
try {
297-
final PollingState<T> pollingState = new PollingState<>(response, getLongRunningOperationRetryTimeout(), resourceType, restClient().serializerAdapter());
301+
final PollingState<T> pollingState = new PollingState<>(response, longRunningOperationRetryTimeout(), resourceType, restClient().serializerAdapter());
298302
return Observable.just(pollingState)
299303
.subscribeOn(Schedulers.io())
300304
// Emit a polling task intermittently

azure-client-runtime/src/main/java/com/microsoft/azure/PollingState.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class PollingState<T> {
2929
/** The link in 'Location' Header. */
3030
private String locationHeaderLink;
3131
/** The timeout interval between two polling operations. */
32-
private Integer retryTimeout;
32+
private int retryTimeout;
3333
/** The response resource object. */
3434
private T resource;
3535
/** The type of the response resource object. */
@@ -48,7 +48,7 @@ final class PollingState<T> {
4848
* @param serializerAdapter the adapter for the Jackson object mapper
4949
* @throws IOException thrown by deserialization
5050
*/
51-
PollingState(Response<ResponseBody> response, Integer retryTimeout, Type resourceType, SerializerAdapter<?> serializerAdapter) throws IOException {
51+
PollingState(Response<ResponseBody> response, int retryTimeout, Type resourceType, SerializerAdapter<?> serializerAdapter) throws IOException {
5252
this.retryTimeout = retryTimeout;
5353
this.withResponse(response);
5454
this.resourceType = resourceType;
@@ -140,7 +140,7 @@ void updateFromResponseOnDeletePost(Response<ResponseBody> response) throws IOEx
140140
* @return the delay in milliseconds.
141141
*/
142142
int delayInMilliseconds() {
143-
if (this.retryTimeout != null) {
143+
if (this.retryTimeout >= 0) {
144144
return this.retryTimeout * 1000;
145145
}
146146
if (this.response != null && response.headers().get("Retry-After") != null) {

0 commit comments

Comments
 (0)