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

[BUG] /tmp/npm-${PID}-* directories should be cleaned when "npm pack" gets terminated #695

Closed
AlexanderSamoilov opened this issue Jan 16, 2020 · 3 comments
Labels
Bug thing that needs fixing

Comments

@AlexanderSamoilov
Copy link

AlexanderSamoilov commented Jan 16, 2020

What / Why

"npm pack" call produces junk data in the system temp (smth like /tmp/npm-8452-4aa95566). This useless data quickly populates the /tmp and puts responsibility on npm users to clean it. I think the responsibility to remove this data should be on npm code, because npm code produces there intermediate directories. I think it is not a big deal to add a removal upon exiting of the npm process.

UPDATE: I am talking about the case "npm pack" failed and did not clean the folder. There should be some error handling added so that npm cleans the temp folder before gets abnormally terminated.

I assume that the place where this path is evaluated is probably ./lib/npm.js, thus probably the removal can be added to this script:
Object.defineProperty(npm, 'tmp',
{
get: function () {
if (!tmpFolder) tmpFolder = 'npm-' + process.pid + '-' + rand
return path.resolve(npm.config.get('tmp'), tmpFolder)
},
enumerable: true
})

OS: Ubuntu 18.04
NPM: 6.5.0

When

Whenever "npm pack" fails.

Where

npm publish

How

Current Behavior

  • n/a

Steps to Reproduce

  • n/a

Expected Behavior

  • n/a

Who

  • n/a

References

  • n/a
@AlexanderSamoilov AlexanderSamoilov changed the title [BUG] /tmp/npm-${PID}-* directories should be cleaned [BUG] /tmp/npm-${PID}-* directories should be cleaned when "npm pack" gets terminated Jan 16, 2020
@ljharb
Copy link
Contributor

ljharb commented Jan 16, 2020

Typically it’s the OS’s job to clean up the temp dir, not the user’s nor applications’. That’s it’s purpose.

@AlexanderSamoilov
Copy link
Author

@ljharb, even if we assume that we both agree with your general formulation the fact is that npm already cleans these temp directories if it successfully exits and in this case the remaining directories have size 1Mb which is fully aceptable for me, because can be cleaned afterwards by the OS as you said:
$ du -ms /tmp/npm-*
1 /tmp/npm-19300-5dc16931
1 /tmp/npm-27233-198faf4e
1 /tmp/npm-27893-20fd4542
1 /tmp/npm-27919-5a5102a4
...
The problem is that the removal is not called in some error cases and then these directories contain large binary data. That is, my request is not about adding of a new feature, but about the improving/fixing of the existing feature.

About the "typically" I would argue about that. From my point of view the remaining intermediate data looks like a memory leak or like a file descriptor which remains open()ed after the program exiting. Many applications write files to /tmp and remove them without delegating it to the OS.
Just imagine that we run not only npm cli on a build server, but a lot of other builds which create a remove tones of data in /tmp in parallel. If all this software had not cleaned their temp data then even the daily clean of /tmp would have not been sufficient. Total explicit cleaning of /tmp is also a bad solution, because in this case you must clearly define the time when no build process is running on the build server, otherwise you make the jobs which are currently using /tmp to fail etc.

But as I already said npm does clean, but sometimes terminates without doing this. I think fixing of this would be a good improvement.

@darcyclarke darcyclarke added the Bug thing that needs fixing label Oct 30, 2020
@darcyclarke
Copy link
Contributor

npm v6 is no longer in active development; We will continue to push security releases to v6 at our team's discretion as-per our Support Policy.

If your bug is preproducible on v7, please re-file this issue using our new issue template.

If your issue was a feature request, please consider opening a new RRFC or RFC. If your issue was a question or other idea that was not CLI-specific, consider opening a discussion on our feedback repo

Closing: This is an automated message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing
Projects
None yet
Development

No branches or pull requests

3 participants