There is a table say company. If we try to get the company by it primary key we get the following error. PLEASE NOTE: This error is not for all instances. It is not repeatedly getting failed. It occurs sometimes but often. 20% of requests are failing
{ Error: getaddrinfo EMFILE dynamodb.eu-west-1.amazonaws.com:443
at Object._errnoException (util.js:1022:11)
at errnoException (dns.js:55:15)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
message: 'getaddrinfo EMFILE dynamodb.eu-west-1.amazonaws.com:443',
code: 'NetworkingError',
errno: 'EMFILE',
syscall: 'getaddrinfo',
hostname: 'dynamodb.eu-west-1.amazonaws.com',
host: 'dynamodb.eu-west-1.amazonaws.com',
port: 443,
region: 'eu-west-1',
retryable: true,
time: 2019-07-18T05:30:09.145Z }
There was a discussion on aws/aws-sdk-js-v3 with issue #3019 where it was recommended to lower the socket timeouts.
This happened to me too when I used the agent as below
new https.Agent({
keepAlive: true,
maxSockets: Infinity,
}
Then I looked more into the documentation here at Reusing Connections with Keep-Alive in Node.js and what I found was an interesting thing
The easiest way to configure SDK for JavaScript to reuse TCP connections is to set the
AWS_NODEJS_CONNECTION_REUSE_ENABLEDenvironment variable to1. This feature was added in the 2.463.0 release.
So, I removed the httpsAgent from the AWS DynamoDBClient connection and added the required environment variable -
AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
The error was resolved and things were working as expected.
I hope somebody might find this answer helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With