Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions sdk/cosmosdb/cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bugs Fixed

- Fixed bugs in session token clearing logic. Session Not found (404, substatus 1002) was not being handled correctly by the session retry policy and would mistakenly retry the request with the same session token.

### Other Changes

## 3.13.0 (2021-08-10)
Expand Down Expand Up @@ -41,8 +43,10 @@
## 3.12.0 (2021-07-06)

### Features Added

- With the dropping of support for Node.js versions that are no longer in LTS, the dependency on `@types/node` has been updated to version 12. Read our [support policy](https://github.com/Azure/azure-sdk-for-js/blob/main/SUPPORT.md) for more details.
- Added background refresher for endpoints, and new `ConnectionPolicy` options. Refreshing defaults to true, and the default refresh rate is every 5 minutes.

```js
const client = new CosmosClient({
endpoint,
Expand All @@ -52,13 +56,14 @@ const client = new CosmosClient({
endpointRefreshRateInMs: 700,
enableBackgroundEndpointRefreshing: true
}
})
});
```

- Added `client.dispose()` for closing the endpoint refresher verbosely. Necessary when destroying the CosmosClient inside existing processes like an express web server, or when you want to destroy the client and create a new one in the same process.

```js
const client = new CosmosClient()
client.dispose() // cancels background endpoint refreshing
const client = new CosmosClient();
client.dispose(); // cancels background endpoint refreshing
```

## 3.11.5 (2021-06-10)
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmosdb/cosmos/src/retry/RetryContext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
export interface RetryContext {
retryCount?: number;
retryCount: number;
retryRequestOnPreferredLocations?: boolean;
clearSessionTokenNotAvailable?: boolean;
}
3 changes: 2 additions & 1 deletion sdk/cosmosdb/cosmos/src/retry/retryUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface RetryPolicies {
* @hidden
*/
export async function execute({
retryContext = {},
retryContext = { retryCount: 0 },
retryPolicies,
requestContext,
executeRequest
Expand Down Expand Up @@ -64,6 +64,7 @@ export async function execute({
}
if (retryContext && retryContext.clearSessionTokenNotAvailable) {
requestContext.client.clearSessionToken(requestContext.path);
delete requestContext.headers["x-ms-session-token"];
}
requestContext.endpoint = await requestContext.globalEndpointManager.resolveServiceEndpoint(
requestContext.resourceType,
Expand Down
6 changes: 4 additions & 2 deletions sdk/cosmosdb/cosmos/src/retry/sessionRetryPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export class SessionRetryPolicy implements RetryPolicy {
if (this.currentRetryAttemptCount > endpoints.length) {
return false;
} else {
retryContext.retryCount = ++this.currentRetryAttemptCount - 1;
this.currentRetryAttemptCount++;
retryContext.retryCount++;
retryContext.retryRequestOnPreferredLocations = this.currentRetryAttemptCount > 1;
retryContext.clearSessionTokenNotAvailable =
this.currentRetryAttemptCount === endpoints.length;
Expand All @@ -66,7 +67,8 @@ export class SessionRetryPolicy implements RetryPolicy {
if (this.currentRetryAttemptCount > 1) {
return false;
} else {
retryContext.retryCount = ++this.currentRetryAttemptCount - 1;
this.currentRetryAttemptCount++;
retryContext.retryCount++;
retryContext.retryRequestOnPreferredLocations = false; // Forces all operations to primary write endpoint
retryContext.clearSessionTokenNotAvailable = true;
return true;
Expand Down
Loading