Azure/azure-cosmos-js

Await Initial Endpoint Discovery Call

Closed this issue · 0 comments

As part of client initialization, the SDK executes a request to resolve all regional endpoints for a database account: https://github.com/Azure/azure-cosmos-js/blob/master/src/CosmosClient.ts#L86 Once we resolve the endpoints, the SDK transparently switches to them instead of the user-supplied global endpoint.

Regional example: yourdb-eastus.documents.azure.com
Global: example: yourdb.documents.azure.com

This initial call doesn't block, so it is possible to start executing other API calls. The SDK will happily execute these against the global endpoint. In port constrained, high concurrency situations, this leads to undesirable behavior.

A large number of sockets will be opened against the global endpoint before the regional endpoints are resolved. When the SDK switches to the regional endpoints, these global sockets won't close. With keepAlive on (still our recommendation and default) they will remain open for ~120s until closed from the server-side.

Fix: We should await the initial resolution of regional endpoints. Users can opt-out of this behavior by setting enableEndpointDiscovery to false