Share via

MongoDB ECONNREFUSED

Kheang Hok Chin 20 Reputation points
2026-02-11T16:15:46.98+00:00

Hi,

We have an azure function app that is unable to connect to our cluster for some reason, we did not change anything.

Here is the error I see in the logs:

2026-02-11T15:13:03.132 [Information] Error: querySrv ECONNREFUSED _mongodb._tcp.<>.azure.mongodb.net at QueryReqWrap.onresolve [as oncomplete] (node:internal/dns/promises:292:17) { errno: undefined, code: 'ECONNREFUSED', syscall: 'querySrv', hostname: '_mongodb._tcp.<>.azure.mongodb.net' }

Any help is appreciated. Other functions apps work.

The URL endpoint and credentials are correct.

I also discussed with MongoDB team and it isn't an issue on their end. We did nslookup tests and the cluster address was resolved successfully. We tried testing a custom dns and it did not solve the issue.

We were able to do a bypass to get it working but why would it affect only one of my function apps.

Thanks.

Azure Functions
Azure Functions

An Azure service that provides an event-driven serverless compute platform.

{count} votes

Answer accepted by question author
  1. Siddhesh Desai 3,935 Reputation points Microsoft External Staff Moderator
    2026-02-11T17:47:37.2733333+00:00

    Hi @Kheang Hok Chin

    Thank you for reaching out to Microsoft Q&A.

    Posting this as an answer to help other community members facing the same issue.

    The issue was related to: https://github.com/nodejs/node/issues/61435

    This was a nodejs issue #61435. You reverted the version.

    If the resolution was helpful, kindly take a moment to click on 210246-screenshot-2021-12-10-121802.pngand click on Yes for was this answer helpful. And, if you have any further query do let us know.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Q&A Assist
    2026-02-11T16:15:59.27+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    The ECONNREFUSED error typically indicates that the connection to the specified MongoDB server was refused. Since you mentioned that other function apps are working and the credentials and endpoint are correct, here are some potential reasons and troubleshooting steps you can consider:

    1. Firewall or Network Restrictions: Ensure that there are no firewall rules or network restrictions preventing the specific function app from accessing the MongoDB cluster. Check the inbound IP restrictions for your function app to ensure it can reach the MongoDB service.
    2. DNS Configuration: Since you performed nslookup tests successfully, the DNS resolution seems to be working. However, ensure that the DNS settings in your Azure Function app are correctly configured to use the appropriate DNS servers.
    3. App Service Environment (ASE): If your function app is hosted in an internally load-balanced App Service Environment, it might be configured to block outbound internet traffic. Verify the network security group (NSG) settings for the ASE and ensure that they allow outbound traffic to the MongoDB cluster.
    4. Connection Pooling Issues: If your app uses connection pooling, it may be possible that the connections are timing out or being dropped. Consider reviewing the connection settings and implementing keep-alive settings to maintain active connections.
    5. Resource Constraints: Check if the function app is experiencing resource constraints (like memory or CPU) that might affect its ability to establish new connections.

    If the issue persists after checking these points, consider enabling detailed logging for your Azure Function app to gather more information about the connection attempts and any underlying issues.


    References:

    0 comments No comments

Your answer

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