Connecting issues

Hi Team,

We are facing below error…

Can any one please explain regarding below error and how can we resolve it?

2023-02-17T13:49:05.811Z	d3a68076-d393-4203-9248-a1e3cd1e9584	INFO	MongoNetworkError: getaddrinfo EMFILE
    at connectionFailureError (/var/task/file-info/file-info-controller.js:90731:18)
    at TLSSocket.<anonymous> (/var/task/file-info/file-info-controller.js:90656:20)
    at Object.onceWrapper (events.js:520:26)
    at TLSSocket.emit (events.js:400:28)
    at TLSSocket.emit (domain.js:475:12)
    at emitErrorNT (internal/streams/destroy.js:106:8)
    at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    at processTicksAndRejections (internal/process/task_queues.js:82:21) {
  cause: Error: getaddrinfo EMFILE
      at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:71:26) {
    errno: -24,
    code: 'EMFILE',
    syscall: 'getaddrinfo',
    hostname: ''
  connectionGeneration: 0,
  [Symbol(errorLabels)]: Set(1) { 'ResetPool' }

Can please help me on this error…

We are getting same error frequently, Is this related to MongoDB or any other?

Thanks in advance…

and also getting {"connectionGeneration":0} error also…

It looks like your code keeps opening new connections without closing the previous one.

EMFILE error means that the OS denied your application from opening new connection because it is using too many.

Thanks @steevej for response,

Code closes the connections immediately without any ideal connections… But concurrent hits gone be high at the time.

How can we handle too many hits in per second? (More then 30k to 40k hits per second)

We are using atlas M400 (SSD class) tier. It has max 1,28,000 connections. Is it reached?

Is there any better way to handle the connections?

Is this error related to MongoDB or Node.js server ?

Not a MongoDB or Node.js issue. It is a code issue. It is a limit of your OS.

Are you opening a connection for each and every


Do not open a connections for each hit.

@Lokesh_D1 You need to open a support ticket with the Technical Services Team.

This error will need MongoDB Engineering to analyze and is Atlas side by the looks of it.

You can try subscribing to the free trial for MongoDB Support via Atlas Developer Tier and submitting a ticket. The technical services rep will open an internal ticket and have engineering look deeper into it.

Thanks @steevej and @Brock