fs: don't fail with EBADF on double close#2955
fs: don't fail with EBADF on double close#2955bnoordhuis wants to merge 1 commit intonodejs:masterfrom
Conversation
|
I am not sure how the second close event is emitted. First time closed and fd is set as null. If self.fd !== number, then close is registered with open and returned immediately. |
|
Both calls to |
|
@bnoordhuis Is there a reason why this function receives an It looks like the argument |
|
@ChALkeR It cannot. Look for the corresponding 'open' event ~90 lines up. The callback is sometimes called with an fd and sometimes not. |
|
@bnoordhuis Ok, true. But when it is — |
|
Virtual shrug. I didn't write that code and I'm not really inclined to change it for risk of breaking something. I could change the guard to |
|
@bnoordhuis Seems reasonable.
Forget that, it's good as it is. LGTM. |
If I understand you correctly, that can't happen, |
Calling fs.ReadStream#close() or fs.WriteStream#close() twice made it try to close the file descriptor twice, with the second attempt using the nulled out `.fd` property and failing with an EBADF error. Fixes: nodejs#2950
|
Updated, PTAL. CI: https://ci.nodejs.org/job/node-test-pull-request/382/ EDIT: Interestingly, the proposed change breaks the tests from this PR because the file descriptor is emitted as part of the |
lib/fs.js
Outdated
There was a problem hiding this comment.
Why not emit an error after it is already closed? Does calling .close() twice on a stream count as a programmer error? If yes, perhaps it shouldn't be thrown under the rug.
|
@bnoordhuis ... still an issue? |
|
Does not appear to be happening in master or v5. Closing |
|
@jasnell I just tested this on v4 and v5 and the included tests do fail there. |
|
Ok. Then there's a fix that needs to be backported it seems. This particular PR is against master. If we can isolate the change that fixed it we can cherry pick that back. |
|
@jasnell I also just tried it on master and it fails there as well, so it looks like this is still applicable everywhere... |
|
Extremely odd. I am not seeing the same results. :-/ ... Ok, thanks for On Sun, Apr 10, 2016 at 5:07 PM, Brian White notifications@github.com
|
|
Hmm.. odd... if I run the test by itself, it fails as reported. If I run the same sequence through the REPL, there's no error: |
|
@jasnell that makes sense because of the timing. The two |
|
Ah, right. Ok. Makes sense.
|
|
Been a while since this was run through CI, so... |
|
In retrospect I don't think silently ignoring the second close call is a good idea. Closing. |
Calling fs.ReadStream#close() or fs.WriteStream#close() twice made it
try to close the file descriptor twice, with the second attempt using
the nulled out
.fdproperty and failing with an EBADF error.Fixes: #2950
CI: https://ci.nodejs.org/job/node-test-pull-request/342/