question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Hitting the exception 'cannot make a new request because the previous response is still open: please call response.close()'

See original GitHub issue

Describe the bug While using the Azure java SDK to make API calls to Azure, we faced this issue. After making a few number of requests to the list storage accounts API call, we hit the exception java.lang.RuntimeException: java.io.IOException: java.lang.IllegalStateException: cannot make a new request because the previous response is still open: please call response.close()

Exception or Stack Trace

java.lang.RuntimeException: java.io.IOException: java.lang.IllegalStateException: cannot make a new request because the previous response is still open: please call response.close()
        at rx.exceptions.Exceptions.propagate(Exceptions.java:57) ~[sd-0.1.jar:?]
        at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:463) ~[sd-0.1.jar:?]
        at rx.observables.BlockingObservable.single(BlockingObservable.java:340) ~[sd-0.1.jar:?]
        at com.microsoft.azure.management.compute.implementation.VirtualMachinesInner$61.nextPage(VirtualMachinesInner.java:1749) ~[sd-0.1.jar:?]
        at com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter$2.nextPage(PagedListConverter.java:70) ~[sd-0.1.jar:?]
        at com.microsoft.azure.PagedList.cachePage(PagedList.java:62) ~[sd-0.1.jar:?]
        at com.microsoft.azure.PagedList.<init>(PagedList.java:56) ~[sd-0.1.jar:?]
        at com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter$2.<init>(PagedListConverter.java:67) ~[sd-0.1.jar:?]
        at com.microsoft.azure.management.resources.fluentcore.utils.PagedListConverter.convert(PagedListConverter.java:67) ~[sd-0.1.jar:?]
        at com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.ReadableWrappersImpl.wrapList(ReadableWrappersImpl.java:43) ~[sd-0.1.jar:?]
        at com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.TopLevelModifiableResourcesImpl.list(TopLevelModifiableResourcesImpl.java:118) ~[sd-0.1.jar:?]


Caused by: java.io.IOException: java.lang.IllegalStateException: cannot make a new request because the previous response is still open: please call response.close()
        at com.microsoft.azure.management.resources.fluentcore.utils.ResourceManagerThrottlingInterceptor.intercept(ResourceManagerThrottlingInterceptor.java:110) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at com.microsoft.azure.management.resources.fluentcore.utils.ProviderRegistrationInterceptor.intercept(ProviderRegistrationInterceptor.java:43) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at com.microsoft.rest.interceptors.BaseUrlHandler.intercept(BaseUrlHandler.java:43) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at com.microsoft.rest.interceptors.RequestIdHeaderInterceptor.intercept(RequestIdHeaderInterceptor.java:29) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:221) ~[sd-0.1.jar:?]
        at okhttp3.RealCall.execute(RealCall.java:81) ~[sd-0.1.jar:?]
        at retrofit2.OkHttpCall.execute(OkHttpCall.java:186) ~[sd-0.1.jar:?]
        at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:40) ~[sd-0.1.jar:?]
        at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:24) ~[sd-0.1.jar:?]
        at rx.Observable.unsafeSubscribe(Observable.java:10327) ~[sd-0.1.jar:?]
        at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48) ~[sd-0.1.jar:?]
        at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33) ~[sd-0.1.jar:?]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) ~[sd-0.1.jar:?]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[sd-0.1.jar:?]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) ~[sd-0.1.jar:?]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[sd-0.1.jar:?]
        at rx.Observable.subscribe(Observable.java:10423) ~[sd-0.1.jar:?]
        at rx.Observable.subscribe(Observable.java:10390) ~[sd-0.1.jar:?]
        at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:443) ~[sd-0.1.jar:?]
        ... 65 more
Caused by: java.lang.IllegalStateException: cannot make a new request because the previous response is still open: please call response.close()
        at okhttp3.internal.connection.Transmitter.newExchange(Transmitter.java:164) ~[sd-0.1.jar:?]
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.java:41) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:94) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:88) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at com.microsoft.rest.retry.RetryHandler.intercept(RetryHandler.java:75) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at com.microsoft.rest.interceptors.CustomHeadersInterceptor.intercept(CustomHeadersInterceptor.java:140) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at com.microsoft.rest.interceptors.UserAgentInterceptor.intercept(UserAgentInterceptor.java:83) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at com.microsoft.azure.credentials.AzureTokenCredentialsInterceptor.intercept(AzureTokenCredentialsInterceptor.java:40) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at com.microsoft.azure.management.resources.fluentcore.utils.ResourceManagerThrottlingInterceptor.intercept(ResourceManagerThrottlingInterceptor.java:108) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at com.microsoft.azure.management.resources.fluentcore.utils.ProviderRegistrationInterceptor.intercept(ProviderRegistrationInterceptor.java:43) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at com.microsoft.rest.interceptors.BaseUrlHandler.intercept(BaseUrlHandler.java:43) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at com.microsoft.rest.interceptors.RequestIdHeaderInterceptor.intercept(RequestIdHeaderInterceptor.java:29) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:142) ~[sd-0.1.jar:?]
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:117) ~[sd-0.1.jar:?]
        at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:221) ~[sd-0.1.jar:?]
        at okhttp3.RealCall.execute(RealCall.java:81) ~[sd-0.1.jar:?]
        at retrofit2.OkHttpCall.execute(OkHttpCall.java:186) ~[sd-0.1.jar:?]
        at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:40) ~[sd-0.1.jar:?]
        at retrofit2.adapter.rxjava.CallExecuteOnSubscribe.call(CallExecuteOnSubscribe.java:24) ~[sd-0.1.jar:?]
        at rx.Observable.unsafeSubscribe(Observable.java:10327) ~[sd-0.1.jar:?]
        at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:48) ~[sd-0.1.jar:?]
        at rx.internal.operators.OnSubscribeMap.call(OnSubscribeMap.java:33) ~[sd-0.1.jar:?]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) ~[sd-0.1.jar:?]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[sd-0.1.jar:?]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48) ~[sd-0.1.jar:?]
        at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[sd-0.1.jar:?]
        at rx.Observable.subscribe(Observable.java:10423) ~[sd-0.1.jar:?]
        at rx.Observable.subscribe(Observable.java:10390) ~[sd-0.1.jar:?]
        at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:443) ~[sd-0.1.jar:?]
        ... 65 more

To Reproduce Created a azure client and called the list storage accounts API call 100 times using the following snippet:

      new ApplicationTokenCredentials(
                          clientId,
                          tenantId,
                          clientSecret,
                          azureEnvironment
                        )

  val azure =
    Azure.configure.withReadTimeout(timeout,TimeUnit.MILLISECONDS).withConnectionTimeout(timeout,TimeUnit.MILLISECONDS).authenticate(appCredentials).withSubscription("<subscriptionId>")

for (i <- 1 to 100) {
	println(i)
	azure.storageAccounts().list()
}

And this fails with the following :

1
<..>
<..>
<..>
99
2019-11-29T15:53:58.237+0530 ERROR <.main> [compute.AzureComputeClientImpl]  An unknown exception is thrown. Will not be retrying.
java.lang.RuntimeException: java.io.IOException: java.lang.IllegalStateException: cannot make a new request because the previous response is still open: please call response.close()
	at rx.exceptions.Exceptions.propagate(Exceptions.java:57) ~[generated-intellij-deps.jar:?]
	at rx.observables.BlockingObservable.blockForSingle(BlockingObservable.java:463) ~[generated-intellij-deps.jar:?]
	at rx.observables.BlockingObservable.single(BlockingObservable.java:340) ~[generated-intellij-deps.jar:?]
	at com.microsoft.azure.management.storage.implementation.StorageAccountsInner.list(StorageAccountsInner.java:743) ~[generated-intellij-deps.jar:?]
	at com.microsoft.azure.management.resources.fluentcore.arm.collection.implementation.TopLevelModifiableResourcesImpl.list(TopLevelModifiableResourcesImpl.java:118)

Expected behavior The response should be same everytime and should not give the above exception.

Setup

  • Azure java sdk version : 1.24.2
  • Azure key vault version : 1.2.2

Additional context We started seeing this exception when we recently upgraded out okhttp3 package. Similar issue can be seen here but is closed and should have been resolved with key vault version 1.2.2 : https://github.com/Azure/azure-sdk-for-java/issues/4879

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
ChenTanyicommented, May 21, 2020

@vashisthsaurabh @ashbondu @manuelmazzuola @Tony-A-J-Martin @dy10 I’ve added some response.close in ResourceManagerThrottlingInterceptor, could you have a try with the 1.34.0?

If the exception could be resolved I’ll close this issue. Thanks!

1reaction
Tony-A-J-Martincommented, May 25, 2020

@ChenTanyi , I can confirm that for us, 1.34.0 resolves the response.close() issue. Now, instead of a RuntimeException, we get a CloudException and the retries are successfully carried out eventually resulting in a successful process. 🥳

Thank you for you help @ChenTanyi , it is very much appreciated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

cannot make a new request because the previous response is ...
But I am getting the error as cannot make a new request because the previous response is still open: please call response.close().
Read more >
Is there a problem doing another API call inside interceptor in ...
IllegalStateException : cannot make a new request because the previous response is still open: please call response.close().
Read more >
This is a nice implementation of the AuthInterceptor, however ...
IllegalStateException : cannot make a new request because the previous response is still open: please call response.close().
Read more >
Error handling, "try...catch" - The Modern JavaScript Tutorial
Here we use the catch block only to show the message, but we can do much more: send a new network request, suggest...
Read more >
Database Engine events and errors - SQL Server
Please have available for review the Microsoft SQL Server error log and ... 1101, 17, Yes, Could not allocate a new page for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found