Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@samwen/lambda-emfiles
Advanced tools
A solution to node AWS lambda EMFILE issue. If you spot following errors in your lambda function logs:
...
etc
Most likely, it is caused by exceeding the file descriptors limit of AWS lambda.
lambda-emfiles provides solution to the problem.
npm install @samwen/lambda-emfiles
const lambda_emfiles = require('@samwen/lambda-emfiles'); exports.handler = async (event) => { try { await lambda_emfiles.start_verify(); ... your code ... } catch (err) { ... error handle code ... } finally { ... code to close and release resources ... await lambda_emfiles.final_check(); } return 'OK'; }; output by lambda_emfiles: example 1: *** new process, emfiles count: 23 ... ... *** emfiles count: 24, leaks: 1 example 2: *** old process, emfiles count: 24 ... ... *** emfiles count: 33, leaks: 9 example 3: *** old process, emfiles count: 890 ... ... *** emfiles count: 910, leaks: 20 Runtime exited with error: exit status 1 Runtime.ExitError
AWS lambda process runs within a docker container in Amazon Linux environment. The maximum limit on file descriptors is 1000. Normally, it is very hard for a lambda function to exceed the limit.
However, the lambda process within the container may be reused for performance optimization.
This is the reason for most cases of exceeding file descriptors limit.
A lambda function leaks 100 file descriptors each time. It will hit the limit in abut 10 runs.
The chance that the lambda process is reused 10 times is really low.
This is why the lambda runs OK for most of times.
But you can spot few errors caused by exceeding file descriptors limit after a while, it depends on how frequently the lambda is running and the concurrency level of the lambda.
The best solution to the problem is to fix file descriptor leakage. lambda-emfiles provides report for this.
It takes time to fix file descriptor leakage, specially it works most of times.
Alternatively, lambda-emfiles calls process.exit(1) when it predicts a deficit of file descriptors in next run. Once the process is gone, it will not reused.
The 2 public methods come with default values for max_emfiles_needed and exit_process. The default values should work for most scenarios.
async start_verify(max_emfiles_needed = 100, exit_process = false) async lambda_emfiles.final_check(max_emfiles_needed = 100, exit_process = true)
max_emfiles_needed: is the estimated max file descriptors will open in the same time.
exit_process: if it is true, it instructs lambda-emfiles to call process.exit(1), when it sees a deficit of file descriptors.
FAQs
solve node AWS lambda EMFILE issue
We found that @samwen/lambda-emfiles demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.