Sreeragh A R
Sreeragh A R

Reputation: 3021

Intermitent EAI_AGAIN error on node server

My nodejs application connects to an external url and uses the response. The application works fine most of the time, but I am getting EAI_AGAIN occasionally.

error:{code:EAI_AGAIN, errno:EAI_AGAIN,syscall:getaddrinfo,hostname:**.com,host:***.com,port:443}

I went through some questions related to EAI_AGAIN. Did not solve my purpose. Saw that this error occurs when DNS name resolving fails.

My concerns are

1) When I checked the logs. There were many successful requests just before the failed request and also there were many successful requests just after the failed request. Why did it fail for only one request?

2) What could be the actual cause? I would like to know all the possibilities.

3) Can the reason be an issue on the external service to which we are connecting?

4) Will be great if anyone can help to recreate the issue.

Note: We are using docker containers. If this has anything to do.

Upvotes: 7

Views: 9474

Answers (1)

Liam Kelly
Liam Kelly

Reputation: 3714

Background

Under the hood, the error is coming from the getaddrinfo syscall. This triggers the OS to perform a DNS query 99% of the time. Looking at the man page for getaddrinfo we see the following concerning the EAI_AGAIN error:

   EAI_AGAIN
          The name server returned a temporary failure indication.  Try
          again later.

This basically tells us that when we see this error, the DNS server (name server) gave us a bad response. It could be burdened somehow and either actively respond with an error or not respond at all.

Questions

  1. The error depends on the DNS server's state, which can be non-deterministic from your perspective, but probably correlated to request rate. You can see if the error appears more often when you have another program (see #4) slam the DNS server.
  2. See #1
  3. Yes, see #1
  4. Load test your DNS server with the following steps and then run your program and see if it happens more often.

Upvotes: 7

Related Questions