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

Fix "Cannot set property closed of" on Node 18 #836

Merged
merged 3 commits into from May 17, 2022

Conversation

dsokal
Copy link
Contributor

@dsokal dsokal commented May 11, 2022

Fixes #828

I'm not an expert on Node internals but from briefly reading the source code, it seems the problem is that .closed doesn't have a setter since Node 18 (https://github.com/nodejs/node/blob/v18.0.0/lib/internal/streams/readable.js#L1243).

The fix is to check whether this._readableState.closed / this._writableState.closed exists and use it instead of this.closed. This mimics other setters from the Readable/Writable class.

I also upgraded the node image in CI - to use Node 18.

The test plan is I guess just to see if CI checks pass. I saw #829 and it seems the tests failed there. From my understanding, if my fix is correct, CI checks should pass now. I also ran yarn test locally on Node 18.1 and it succeeded.

src/volume.ts Outdated
// Since Node 18, there is only a getter for '.closed'.
// The first branch mimics other setters from Readable.
// See https://github.com/nodejs/node/blob/v18.0.0/lib/internal/streams/readable.js#L1243
if (this._readableState && typeof this._readableState.closed === 'boolean') {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (this._readableState && typeof this._readableState.closed === 'boolean') {
if (typeof this._readableState?.closed === 'boolean') {

It should be possible to use optional chaining here right?

@dsokal
Copy link
Contributor Author

dsokal commented May 12, 2022

@G-Rath I addressed your feedback and also realized that I should fix the FsWriteStream implementation. I decided to copy-paste the close method from FsReadStream because in my opinion sth like the following would look weird:

  if (typeof this._readableState?.closed === 'boolean') {
    this._readableState.closed = true;
  } else if (typeof this._writableState?.closed === 'boolean') {
    this._writableState.closed = true;
  } else {
    this.closed = true;
  }

Especially because _writableState does not exist for ReadStream.

But I can change it, whatever you prefer.

@dsokal
Copy link
Contributor Author

dsokal commented May 17, 2022

@G-Rath just a friendly reminder about this PR.

@ianlavapiez
Copy link

^^ for this merge request.

@G-Rath G-Rath merged commit d1823e1 into streamich:master May 17, 2022
streamich pushed a commit that referenced this pull request May 17, 2022
## [3.4.2](v3.4.1...v3.4.2) (2022-05-17)

### Bug Fixes

* set `closed` property correct on Node 18 ([#836](#836)) ([d1823e1](d1823e1))
@streamich
Copy link
Owner

🎉 This PR is included in version 3.4.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@@ -3,7 +3,7 @@ version: 2
refs:
container: &container
docker:
- image: node:14
- image: node:18
Copy link

@pratik136 pratik136 May 20, 2022

Choose a reason for hiding this comment

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

I'm inclined to believe that the library should be simultaneously tested on all LTS versions of Node.js in addition to at least the major versions of the recent ones.

Theoretically they all are in active dev, or maintenance, and as such bear the potential to break. If the e2e test suite could be run on all versions, that can act as the first line of defence. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree. I simply changed this value because I'm not a maintainer/code-owner of this lib and this was the easiest I could do to make sure it works on Node 18.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot set property closed of #<Readable> which has only a getter in NodeJS v18.0.0
5 participants