Shabnas_M
(Shabnas M)
August 23, 2022, 7:13am
1
Hey,
I’m using MongoDB Serverless with for my Node.js hosted on a lightsail server. Rarely like once in a week or two, I find errors in the logs which look like this
getaddrinfo EAI_AGAIN xxxx-yy.zzzzz.mongodb.net
Looks like the connection to the db has been lost, I’ve been tackling w this issue for a while now, so I added listeners on disconnect
and error
events to try to reconnect in 2secs, but I can see it wasn’t of much help as its the same error for another 10 tries and eventually the server crashes.
Restarting the server and everything works pretty smooth again
1 Like
Having the same issue. Similar setup.
Shabnas_M:
Hey,
I’m using MongoDB Serverless with for my Node.js hosted on a lightsail server. Rarely like once in a week or two, I find errors in the logs which look like this
getaddrinfo EAI_AGAIN xxxx-yy.zzzzz.mongodb.net
Looks like the connection to the db has been lost, I’ve been tackling w this issue for a while now, so I added listeners on disconnect
and error
events to try to reconnect in 2secs, but I can see it wasn’t of much help as its the same error for another 10 tries and eventually the server crashes.
Restarting the server and everything works pretty smooth again
This error typically indicates a DNS resolution problem. Here are a few steps you can try:
Increase Timeout and Retry Logic : Implement a more robust retry mechanism with exponential backoff and increase the timeout duration between retries.
Use a DNS Cache : Consider using a DNS caching service like dnsmasq
to reduce DNS lookup times.
Check DNS Configuration : Verify your server’s DNS settings. You might try using Google’s DNS (8.8.8.8
and 8.8.4.4
) or Cloudflare’s (1.1.1.1
).
Network Stability : Ensure your server’s network connection is stable. Occasionally, intermittent network issues can cause these errors.
Update MongoDB Driver : Ensure you’re using the latest version of the MongoDB Node.js driver, as updates might include bug fixes or improvements.
Monitor Resource Usage : Check if your server is running out of memory or CPU, which might affect DNS resolution.
Contact Hosting Support : If the issue persists, reaching out to your hosting provider might help identify if there are any network-level issues.
Implementing these strategies could help reduce or eliminate the occurrence of this error.