Skip to content
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

Build bug: process PID reuse with non-cleaned-up tmp directory #318

Closed
chriskrycho opened this issue Sep 24, 2018 · 1 comment
Closed

Build bug: process PID reuse with non-cleaned-up tmp directory #318

chriskrycho opened this issue Sep 24, 2018 · 1 comment
Labels
bug build Ideas for or bugs with the build process

Comments

@chriskrycho
Copy link
Member

chriskrycho commented Sep 24, 2018

The Bug

We use the process.pid for building the output directory:

let outDir = path.join(tmpdir(), `e-c-ts-${process.pid}`);

This can cause different builds (even from different apps) to end up with the same directory in the build tree. Here's the scenario where we triggered it:

  • running on CI, so reusing the same local directory for various apps (because it's just getting checked out to some default checkout directory)
  • the system temp directory we created doesn't get deleted for some reason (we don't delete it in e-c-ts at all as far I can see)
  • the PID happens to get recycled

When this happens, the actual same folder on disk gets reused, and you can end up with build artifacts from a previous build – including from totally separate applications! – in the build pipeline, causing runtime require resolution errors or similarly weird behaviors.

  1. We should generate a UUID or some such for those to make sure that this kind of collision isn't possible.
  2. We should be good citizens and clear the directory when we're done.
@chriskrycho chriskrycho added bug build Ideas for or bugs with the build process labels Sep 24, 2018
@chriskrycho
Copy link
Member Author

Suggestion: replace use of pid with an actual uuid.

chriskrycho added a commit that referenced this issue Sep 24, 2018
While the system temp directory gets cleaned up semi-regularly,
on long-running machines (e.g. CI servers), it is possible for
the PID to get reused before the system temp directory gets
cleared. When this happens, the temp directory we create as an
intermediate location for TypeScript build artifacts (to prevent
churn in the build) can end up being used for multiple builds,
even across separate apps. This can result in very bad output
from the build, including total runtime failures from things like
`require` entries including files from different builds or apps.

Prevent this by always running `fs.removeSync` on the temp output
directory prior to setting it and putting new output there.

Fixes #318.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug build Ideas for or bugs with the build process
Projects
None yet
Development

No branches or pull requests

1 participant