-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(pacmak): EMFILE
error when running jsii-pacmak
#1891
Conversation
The `findLocalBuildDirs` function did not have a protection against inspecting the same `package.json` file multiple times, and asynchronously traverses the whole dependency tree under the built package. In certain pathological cases, dependencies could be processed many times around (think about how `@aws-cdk/aws-iam` is a direct or transitive dependency of nearly every other `@aws-cdk/aws-*` module). The asynchronous nature of the process means that *many* instances of the same file could be opened at the same time, occasionally inching above the maximum file descriptor count limit, hence causing `EMFILE` ( which is the standard error code for "too many files open"). This change adds a `visitedDirectories` set to prevent re-visiting the same dependency instance multiple times (based on the absolute path of the package root). This incidentally also improves the performance of the process, since making promises incurs overhead, and not re-processing directories multiple times cut out a significant chunk of the promises made in extreme cases. Special thanks to @richardhboyd for having me look into this particular problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to pull out the recursion and caching logic as a functional method that can be independently tested from the 'result collection' passed as a callback, so that these can be unit tested independently
cea4368
to
9988142
Compare
9988142
to
0adfe53
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it! |
Merging (with squash)... |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Merging (with squash)... |
The
findLocalBuildDirs
function did not have a protection againstinspecting the same
package.json
file multiple times, andasynchronously traverses the whole dependency tree under the built
package. In certain pathological cases, dependencies could be processed
many times around (think about how
@aws-cdk/aws-iam
is a direct ortransitive dependency of nearly every other
@aws-cdk/aws-*
module).The asynchronous nature of the process means that many instances of
the same file could be opened at the same time, occasionally inching
above the maximum file descriptor count limit, hence causing
EMFILE
(which is the standard error code for "too many files open").
This change adds a
visitedDirectories
set to prevent re-visiting thesame dependency instance multiple times (based on the absolute path of
the package root). This incidentally also improves the performance of
the process, since making promises incurs overhead, and not
re-processing directories multiple times cut out a significant chunk of
the promises made in extreme cases.
Special thanks to @richardhboyd for having me look into this particular
problem.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.