Skip to content

Conversation

@mcollina
Copy link
Member

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-botnodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Feb 7, 2017
@jasnell
Copy link
Member

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.

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
MemberAuthor

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
MemberAuthor

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

@mscdex
Copy link
Contributor

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

@mscdex
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.

@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
MemberAuthor

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.

@mcollinamcollina 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
@mcollinamcollina changed the title fs: avoid emitting error EBADF for double closeofs: avoid emitting error EBADF for double closeFeb 13, 2017
@mcollina
Copy link
MemberAuthor

Landed as b1fc774

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]>
@jasnelljasnell mentioned this pull request Apr 4, 2017
@Fishrock123
Copy link
Contributor

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

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

@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

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

@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
MemberAuthor

@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

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

this.once('open',closeOnOpen);// ...functioncloseOnOpen(){this.close(null);}

@mcollina
Copy link
MemberAuthor

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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fsIssues and PRs related to the fs subsystem / file system.semver-majorPRs 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

@mcollina@jasnell@mscdex@evanlucas@Fishrock123@cjihrig@nodejs-github-bot