The server crashes with EMFILE NetworkingError
See original GitHub issueHello,
I’m running an express.js app using the aws-serverless-express
adapter. My app is making some requests to AWS Cognito API using the aws-sdk
module. It’s been in production for many months and from time to time it’s crashing with the following stack trace:
{ Error: listen EMFILE /tmp/server-ck6wudgsnfo.sock
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at Server.setupListenHandle [as _listen2] (net.js:1350:19)
at listenInCluster (net.js:1408:12)
at Server.listen (net.js:1503:5)
at startServer (/var/task/node_modules/aws-serverless-express/src/index.js:152:17)
at Object.proxy (/var/task/node_modules/aws-serverless-express/src/index.js:205:14)
at exports.handler (/var/task/src/serverless/index.js:31:33)
code: 'EMFILE',
errno: 'EMFILE',
syscall: 'listen',
address: '/tmp/server-ck6wudgsnfo.sock',
port: -1
}
It’s caused by the following error in the app. EMFILE
is the error code if there’s no more file descriptors available.
{
message: 'getaddrinfo EMFILE cognito-idp.ap-southeast-2.amazonaws.com:443',
code: 'NetworkingError',
errno: 'EMFILE',
syscall: 'getaddrinfo',
hostname: 'cognito-idp.ap-southeast-2.amazonaws.com',
host: 'cognito-idp.ap-southeast-2.amazonaws.com',
port: 443,
region: 'ap-southeast-2',
retryable: true,
time: '2019-05-28T06:04:43.973Z'
}
Error: getaddrinfo EMFILE cognito-idp.ap-southeast-2.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)
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top Results From Across the Web
"connect EMFILE" error in Node.js - Stack Overflow
EMFILE means error maximum files which indicates that the OS is denying your program to open more file descriptors.
Read more >ERROR: Connection issue EMFILE - AWS re:Post
EMFILE error means that the OS is denying your program to open more files/sockets. Please double check whether you are hitting following system...
Read more >Malformed Lambda Proxy Response With Aws ... - ADocLib
The server crashes with EMFILE NetworkingError hot 19. ERROR: aws-serverless-express connection error with every requests hot 8. source:https://uonfu.com/.
Read more >Intermittent Lambda Layer to Dynamo NetworkingError : r/aws
The calls to this endpoint are in an interval of about 5-10 seconds. The Error I'm getting (not very often):. Error: getaddrinfo EMFILE...
Read more >Timeline - OpenModelica
Fixed encoding. Improved the ZeroMQ server receive method. 20:01 Changeset in OpenModelica [050739d]Added-citation-metadatamaintenance/v1.14 ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@codingyourlife
The reason I had the issue was initializing the internal
aws-serverless-express
server inside the handler function like this:The solution to my issue was to move the server initialization to the global scope so that it’s shared across lambda invocations:
I checked the module that creates the lambda handler and it has been changed recently. The server creation has been moved from the global scope to the lambda handler. Unfortunately, the change hasn’t been noticed in the code review and we didn’t have any automated tests to detect it. I guess it’s time to write a test for it.
So basically every lambda invocation was creating a new listener and after some time it reached the limit of opened file descriptors (for lambda functions the limit is 1024)