-
Notifications
You must be signed in to change notification settings - Fork 7.3k
FDs should only open once a file stream is being consumed #6782
Comments
This is the correct behavior of the In reality you should only be creating var s = fs.createReadStream('foo.txt', { fd: -1 });
s.fd = null; The current implementation details mean that since you're giving it an fd it won't try and open by default, and then the checks in |
thanks for your quick response! it's just a little harder to pass around file streams and then decide not to use them, specifically when you're making a framework! not a big deal, especially with that work around! |
is there a reason that ReadStreams are so eager? or is that mostly to retain streams 1 support? definitely awkward api-wise |
the more i think about this, the more i think this is incorrect behavior. there should be a clear distinction between initialization and processing. right now, processing begins at initialization. the API should be: var stream = fs.createReadStream('filename.txt')
stream.read(0) if you want events to emitted ASAP. otherwise, no processing should occur. this won't affect the general use case where the streams are flowing immediately via would you take a PR? /cc @isaacs |
this would probably classify as a breaking change regardless unfortunately :( even though it's supposed to be somewhat transparent |
I agree with @jonathanong that beeing able to separate initialization & processing would be a win in the stream API. I used to do a lot of SIP related things (session initiation protocol) for voice over IP and the most solid APIs were the one were you could take your time to setup / configure the session before starting it. it is not always necessary but once you start handling complex stream graphs (you can think of gstreamer like stream graph for example where each node in the graph can adapt itself depending on the capabilities of the other connected streams), it is better to first build the stream wiring (pipe) and only after this start pumping data in the graph. |
example: https://gist.github.com/jonathanong/8186604
this will cause an EMFILE error, even though none of the streams are ever consumed.
The text was updated successfully, but these errors were encountered: