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

fs: avoid emitting error EBADF for double close #11225

Closed
wants to merge 1 commit into from

Conversation

mcollina
Copy link
Member

@mcollina mcollina commented Feb 7, 2017

Changed the logic in fs.ReadStream and fs.WriteStream so that
close always calls the prototype method rather than the internal
event listener.

Fixes: #2950

cc @evanlucas @Trott @bnoordhuis

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

fs, stream

@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Feb 7, 2017
@jasnell
Copy link
Member

jasnell commented Feb 7, 2017

Given that this affects error handling it technically should be considered for semver-major. However, I think it qualifies as a bug fix so leaving it as semver-patch.


common.refreshTmpDir();

const s = fs.createWriteStream(path.join(common.tmpDir, '/rw'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the / before rw.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Changed the logic in fs.ReadStream and fs.WriteStream so that
close always calls the prototype method rather than the internal
event listener.

Fixes: nodejs#2950
@mcollina
Copy link
Member Author

mcollina commented Feb 7, 2017

@jasnell I added the don't land on LTS labels, just in case.

@mscdex
Copy link
Contributor

mscdex commented Feb 7, 2017

Minor nit: there's a typo in the commit message

@mscdex
Copy link
Contributor

mscdex commented Feb 7, 2017

Another reason not to land on v4.x and v6.x is the use of .bind(), which won't be very fast in those versions.

@evanlucas
Copy link
Contributor

If we aren't planning on backporting this, I think we should go ahead and mark as semver-major (especially given that it seems like a breaking change)

@Fishrock123
Copy link
Contributor

Another reason not to land on v4.x and v6.x is the use of .bind(), which won't be very fast in those versions.

We can just use an arrow function instead?

@mcollina
Copy link
Member Author

mcollina commented Feb 8, 2017

Another reason not to land on v4.x and v6.x is the use of .bind(), which won't be very fast in those versions.

We can just use an arrow function instead?

If that's the only problem, yes of course.

@mcollina mcollina added semver-major PRs that contain breaking changes and should be released in the next major version. and removed dont-land-on-v4.x labels Feb 13, 2017
@mcollina mcollina changed the title fs: avoid emitting error EBADF for double closeo fs: avoid emitting error EBADF for double close Feb 13, 2017
@mcollina
Copy link
Member Author

Landed as b1fc774

@mcollina mcollina closed this Feb 13, 2017
mcollina added a commit that referenced this pull request Feb 13, 2017
Changed the logic in fs.ReadStream and fs.WriteStream so that
close always calls the prototype method rather than the internal
event listener.

Fixes: #2950
PR-URL: #11225
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
krydos pushed a commit to krydos/node that referenced this pull request Feb 25, 2017
Changed the logic in fs.ReadStream and fs.WriteStream so that
close always calls the prototype method rather than the internal
event listener.

Fixes: nodejs#2950
PR-URL: nodejs#11225
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
@jasnell jasnell mentioned this pull request Apr 4, 2017
@Fishrock123
Copy link
Contributor

@jasnell @mcollina Was this intentionally left as semver-major?

@mcollina mcollina deleted the fix-2950 branch June 2, 2017 07:31
@mcollina
Copy link
Member Author

mcollina commented Jun 2, 2017

@Fishrock123 yes. I'm happy for it to be backported, but we were not in agreement. If we agree that this is not semver-major, we can backport. I can fire a PR.

cc @jasnell @evanlucas @mscdex @cjihrig

@cjihrig
Copy link
Contributor

cjihrig commented Jun 3, 2017

I don't know if this is pressing enough that it needs to be backported, but I don't feel strongly either way.

@mscdex
Copy link
Contributor

mscdex commented Jun 3, 2017

@mcollina Now that I look at this again, I think we could have avoided the bind() with just:

this.once('open', this.close);

which is more easily backportable. Maybe submit a separate PR for the bind() removal and then backport this and that PR at the same time?

@mcollina
Copy link
Member Author

mcollina commented Jun 5, 2017

@mscdex we cannot, because open will be emitted with the fd as the first argument. If we want to change this, we need to change the check on cb, so that it ignores anything that is not a function. As calling close()  when a stream is not open yet is likely not a hot path, I don't think it's worth the added complexity.

@mscdex
Copy link
Contributor

mscdex commented Jun 5, 2017

@mcollina Ok well we could still pull out a reusable function and do it that way:

this.once('open', closeOnOpen);

// ...

function closeOnOpen() {
  this.close(null);
}

@mcollina
Copy link
Member Author

mcollina commented Jun 5, 2017

here it is: #13474

mcollina added a commit to mcollina/node that referenced this pull request Jun 7, 2017
nodejs#11225 introduce an unnecessary
bind() when closing a stream. This PR replaces that bind() with a
top-level function.

PR-URL: nodejs#13474
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Brian White <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
mcollina added a commit to mcollina/node that referenced this pull request Jun 7, 2017
nodejs#11225 introduce an unnecessary
bind() when closing a stream. This PR replaces that bind() with a
top-level function.

PR-URL: nodejs#13474
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Brian White <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
jasnell pushed a commit that referenced this pull request Jun 7, 2017
#11225 introduce an unnecessary
bind() when closing a stream. This PR replaces that bind() with a
top-level function.

PR-URL: #13474
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Brian White <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"WriteStream.close" from "fs" module not executing the callback
7 participants