Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

fd leak in ReadStream.destroy() #8178

Closed
wants to merge 1 commit into from
Closed

Conversation

rlidwka
Copy link

@rlidwka rlidwka commented Aug 14, 2014

defensive programming is bad sometimes :)

this leaks:

setInterval(function() {
  var x = require('fs').createReadStream('/etc/passwd');
  x.destroy();
}, 1000);

this doesn't:

setInterval(function() {
  var x = require('fs').createReadStream('/etc/passwd');
  x.close();
}, 1000);

all details are here somewhere: pillarjs/send#55

I wonder how do I write tests for those...

@dougwilson
Copy link
Member

The issue does not exist in Node.js 0.8; it looks like a Node.js 0.10 regression.

@dougwilson
Copy link
Member

For all those who are concerned about this: use the destroy module on npm to destroy your streams instead of stream.destroy() :) It'll handle this (and future cases) correctly. Even if Node.js core fixes the issue, it'll of course still be a problem in all the previous v0.10.x releases.

@piscisaureus
Copy link

This looks like something that should just get fixed and back-ported to v0.10.

@dougwilson
Copy link
Member

I meant, still an issue in 0.10.0 to 0.10.30 :)

@aheckmann
Copy link

@dougwilson do you mean the dethroy module?

@Fishrock123
Copy link

@aheckmann dethroy is now destroy: https://www.npmjs.org/package/destroy

@dougwilson
Copy link
Member

Seems weird this fd leak fix didn't make it into 0.10.31 :/

@indutny
Copy link
Member

indutny commented Aug 22, 2014

@rlidwka perhaps we could have a test?

@rlidwka
Copy link
Author

rlidwka commented Aug 22, 2014

@indutny , how do you suggest to make one? I could do exec("lsof") (slow, non-portable, but a sure way), or try to mess with internal state (for example, try do close fd again on timeout and make sure it returns EBADF, but that's unreliable).

@indutny
Copy link
Member

indutny commented Aug 22, 2014

Hm... I wonder if we could limit number of fds programmatically. We do have ulimit -n-kindish call in src/node.cc, but nothing like that in tests... cc @tjfontaine

@trevnorris trevnorris added the fs label Sep 3, 2014
@dougwilson
Copy link
Member

Any update on this? Will this ever make it into a 0.10 release? The leak makes it impossible to prevent fd leaks if you call destroy on ReadStreams. It basically means that ReadStream.prototype.destory is completely unusable in node.js 0.10 (the issue doesn't exist in 0.8).

@dougwilson
Copy link
Member

How about updating the PR to use process._getActiveHandles() to verify?

@rlidwka
Copy link
Author

rlidwka commented Oct 10, 2014

How about updating the PR to use process._getActiveHandles() to verify?

Doesn't work, because leaked fds don't get listed in that array:
https://gist.github.com/rlidwka/7812f3fefd6f63c5bdb4

@dougwilson
Copy link
Member

Darn

@dougwilson
Copy link
Member

@indutny @tjfontaine any recommendations for this PR's tests? The PR fixes a regressions between node 0.8 and 0.10 where 0.10 will leak fds in a common usage with piping files in http servers.

@dougwilson
Copy link
Member

Oh, oh, can we finally get this into a 0.10 patch release??? I see one is cooking up in the v0.10 branch. It'd be nice to have non-leaky things :)

@dougwilson
Copy link
Member

Any test implementation suggestions yet?

@dougwilson
Copy link
Member

@indutny @tjfontaine any suggestions for how the test can be done?

@dougwilson
Copy link
Member

This is a big source of fd leaks in both 0.10 and 0.11.14. 0.8 code does not have this problem, because the regression was introduced after 0.8.

At the very least, this needs to be addressed before 0.12 if you're not going to fix it in 0.10.

@dougwilson
Copy link
Member

cc @misterdjules

@jasnell
Copy link
Member

jasnell commented Aug 16, 2015

@piscisaureus @indutny ... looks like this went stale but nothing was ever changed in v0.10 or v0.12.

@Fishrock123
Copy link

@jasnell this is fixed in io.js, I'll try to dig up the commit later.

@jasnell
Copy link
Member

jasnell commented Aug 16, 2015

Yep saw that. We may want to backport the fix. But this particular PR can be closed.

@jasnell jasnell closed this Aug 16, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants