-
Notifications
You must be signed in to change notification settings - Fork 647
Description
This issue is extracted from this original issue: #3019, like requested: #3019 (comment)
#3019 is concentrated to the readFile (leaking file descriptor) "issue" and this issue is concentrated to the network (leaking file descriptor) "issue"
It seems lambda is not "waiting" for the file descriptors to be closed.
This can be observed especially, when having warm lambda executions with a lot of sdk calls, like for DynamoDb or S3, etc...
This each http request opens a network socket which results in an open file descriptor.
Since by default in Node.js the socket timeout is set to 120000ms (2 minutes) it may be the lambda is already finished, but the sockets are still open. When "restarting" the lambda for the next invocations, those file descriptors may still be open.
This leads to this type of EMFILE errors:
Error: connect EMFILE 52.94.5.100:443 - Local (undefined:undefined)
Error: getaddrinfo EMFILE dynamodb.eu-west-1.amazonaws.com
Error: A system error occurred: uv_os_homedir returned EMFILE (too many open files)
These basic tests shows the count (and leaks) of the emfile count:
Tests originally done in this issue here: #3019 (comment)
compared to this tests: #3019 (comment)
Defining a custom requestHandler, with a very low socketTimeout reduces drastically the emfiles count:
requestHandler: new NodeHttpHandler({
socketTimeout: 10000 // <- this decreases the emfiles count, the Node.js default is 120000
})That's why I suggest to set a low socket Timeout by default, like proposed here: #3019 (comment)
proposal:
// https://github.com/aws/aws-sdk-js-v3/blob/main/packages/node-http-handler/src/node-http-handler.ts#L62
socketTimeout: socketTimeout || 10000and probably also here?
// https://github.com/aws/aws-sdk-js-v3/blob/main/packages/node-http-handler/src/node-http2-handler.ts#L44
this.requestTimeout = requestTimeout || 10000;PS. btw. it seems it got worse (more file descriptors) when updating from v3.46.0 to v3.49.0



