diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ThinClientStoreModel.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ThinClientStoreModel.java index 1bd343e6192b..2a92039ddd7e 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ThinClientStoreModel.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/ThinClientStoreModel.java @@ -135,13 +135,21 @@ public StoreResponse unwrapToStoreResponse( payloadBuf ); + if (payloadBuf != content) { + // payload is a slice/derived view; super() owns payload, we still own the container + // this includes scenarios where payloadBuf == EMPTY_BUFFER + ReferenceCountUtil.safeRelease(content); + } + return storeResponse; - } finally { + } catch (Throwable t){ if (payloadBuf != content) { // payload is a slice/derived view; super() owns payload, we still own the container // this includes scenarios where payloadBuf == EMPTY_BUFFER ReferenceCountUtil.safeRelease(content); } + + throw t; } } diff --git a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/WebExceptionRetryPolicy.java b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/WebExceptionRetryPolicy.java index b1f737530f31..0314d4dea86c 100644 --- a/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/WebExceptionRetryPolicy.java +++ b/sdk/cosmos/azure-cosmos/src/main/java/com/azure/cosmos/implementation/WebExceptionRetryPolicy.java @@ -48,9 +48,9 @@ public Mono shouldRetry(Exception e) { .warn( "WebExceptionRetryPolicy() No retries because client is not initialized yet. - " + "operationType = {}, count = {}, isAddressRefresh = {}", - this.request.getOperationType(), + this.request != null ? this.request.getOperationType() : "n/a", this.retryCount, - this.request.isAddressRefresh()); + this.request != null ? this.request.isAddressRefresh() : "n/a"); return Mono.just(ShouldRetryResult.noRetry()); }