-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix resourse cleaning #570
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
base: v3
Are you sure you want to change the base?
Conversation
For #568 |
Would you mind explaining more what this change does and why you think it's the right approach? I fail to see how this could fix an |
@LinusU It does not fix EPERM error, it's my codebase error. Without this PR files are left opened till process exit if user handler do nothing with them |
… client or stream open
fa0b38c
to
2417c1d
Compare
Hmm, I'm afraid that relying on this could have unintended consequences. For example, I'm not sure that the following code would still work: app.post('/upload', upload.single('file'), async (req, res) => {
res.send(200, 'OK')
const fileName = await allocateFileName()
const target = fs.createWriteStream()
req.file.stream.pipe(target)
}) Basically, I'm not sure (I don't have a definitive decision, just want to bring up discussion) that not using the stream before responding to the http request means that you don't want to use the file. 🤔 |
@LinusU this code should work, but it wrong because it can crash, but user does not get any info about it. I recommend at least get stream before finishing request.
will create tmp file and DOES NOT remove it at any time and takes handle, so app may reach open_files limit and crash. |
I don't think that it does, since the file will have been removed by the time it hits the
That doesn't necessarily make it wrong. There could be plenty of reasons for not wanting to notify the user of errors.
The files should be removed, but I just saw that this does in fact leak file descriptors. Basically it boils down to the underlying FD not beeing freed when the This is potentially something that should be fixed in Node.js, I'll open an issue about that. We could probably use e.g. node-weak to work around that manually for now. |
+1 I noticed in When I re-run the app, only then it is removed. |
request stream by demand, fix fs.unlink to call when response send to client or stream open