Suddenly Get [connect ETIMEDOUT] error when Azure Function calling Cosmos with JS SDK start from last week

Henry Zhang 206 Reputation points
2024-01-15T21:37:10.6433333+00:00

Hi There, One of our prod Azure functions (written in node.js) suddenly started to get a [connect ETIMEDOUT] error when calling Cosmos last week. The function is a timer function that will run every hour, more than 50% of the calls will get this error while the others will succeed. No code change, and no deployment, and the Azure function has run with no issues previously. Our function is using JS SDK to query the cosmos, something like this:

      const { resources } = await this.client
        .database(this.config.database.id)
        .container(this.config.container.id)
        .items.query(querySpec)
        .fetchAll();

The query is something like:

SELECT * FROM c WHERE c.whenCreated >= 'XXXX' AND c.type = 'XXXX'

It is for query items created within the last 2 days for a certain type. I have tried to call cosmos API from my local with postman, the query is always successful and super fast, and the results are only 300 small items.

We tried restarting the function app, it will run smoothly at the beginning but later on will get this ETIMEOUT issue again. Wondering what could be wrong? Thanks, Henry

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,397 questions
Azure
Azure
A cloud computing platform and infrastructure for building, deploying and managing applications and services through a worldwide network of Microsoft-managed datacenters.
1,090 questions
Azure Cosmos DB
Azure Cosmos DB
An Azure NoSQL database service for app development.
1,749 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Henry Zhang 206 Reputation points
    2024-01-25T03:38:43.75+00:00

    I think I figured out, it should be the SNAT port exhaustion issue caused by @Azure/cosmos 3.11.0 version that we are currently using. Github issue: https://github.com/Azure/azure-sdk-for-js/issues/15214

    will try update the SDK and check.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.