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: make SyncWriteStream inherit from Writable #8830

Closed
wants to merge 2 commits into from

Conversation

addaleax
Copy link
Member

@addaleax addaleax commented Sep 28, 2016

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

fs, process?

Description of change

Make the internal SyncWriteStream a proper stream.Writable subclass. This allows for quite a bit of simplification, since SyncWriteStream predates the streams2/streams3 implementations.

Fixes: #8828

I’ve tried to be conservative with the changes here, e.g. by keeping the explicit readable boolean property and by keeping the .destroy() behaviour of emitting an explicit close event, although I doubt that either of these are relied upon.

Make the internal `SyncWriteStream` a proper `stream.Writable`
subclass. This allows for quite a bit of simplification, since
`SyncWriteStream` predates the streams2/streams3 implementations.

Fixes: nodejs#8828
@addaleax addaleax added fs Issues and PRs related to the fs subsystem / file system. stream Issues and PRs related to the stream subsystem. process Issues and PRs related to the process subsystem. labels Sep 28, 2016
@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Sep 28, 2016
// when stdout/stderr point to files.

if (process.argv[2] === 'child') {
console.log(JSON.stringify([process.stdout, process.stderr].map((stdio) => ({
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Perhaps a note here quickly indicating that the console.log is intentional and part of the test? There are plenty of places around in the tests where console.log is used without serving much purpose.

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

LGTM with green CI and citgm.

@addaleax
Copy link
Member Author

@jasnell Done!

CI: https://ci.nodejs.org/job/node-test-commit/5355/
CITGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/399/

Copy link
Contributor

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

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

LGTM if tests pass, maybe also run citgm on it.

That being said, I think this is only a step, and we should switch to net.Socket so that people don't reply on things that may not be in Socket, and don;t have to patch for Socket functionality.

@Fishrock123
Copy link
Contributor

Actually, that is due to an understanding of mine that net.Socket inherits from WriteStream. If it does not, we should probably not proceed with this? Checking...

@Fishrock123
Copy link
Contributor

Hmmm, net.Socket inherits from stream.Duplex, does that change anything here?

@thefourtheye
Copy link
Contributor

cc @nodejs/streams

@addaleax
Copy link
Member Author

Hmmm, net.Socket inherits from stream.Duplex, does that change anything here?

Hmmm. On the one hand, Duplexes are not technically Writables according the prototype chain… on the other hand, we should probably make instanceof work properly for Duplexes using Symbol.hasInstance? I guess I’ll open a PR for that in a bit, too.

@mcollina
Copy link
Member

@Fishrock123

That being said, I think this is only a step, and we should switch to net.Socket so that people don't reply on things that may not be in Socket, and don't have to patch for Socket functionality.

I agree. But that might be a semver-major change.

The debug module depends on SyncWriteStream to be there and working as expected.
@thealphanerd is debug in CITGM?

@addaleax can you verify that debug still works with this change?

I'm flagging this as semver-minor, pending CITGM and the assessment on debug.

@mcollina mcollina added the semver-minor PRs that contain new features and should be released in the next minor version. label Sep 29, 2016
@addaleax
Copy link
Member Author

@thealphanerd is debug in CITGM?

debug doesn’t appear to have a proper test suite? :(

@addaleax can you verify that debug still works with this change?

Ostensibly, yes. I’m not even sure what they are using it for, so I’d probably have to take the time to look into it in more detail.

@mcollina
Copy link
Member

Ostensibly, yes. I’m not even sure what they are using it for, so I’d probably have to take the time to look into it in more detail.

They lifted some code from core back then. Not sure exactly why, so feel free to have a look, you might also want to send them a PR. You can just run any Express app with DEBUG=* and redirect the output to a file, if that works, we are grand with this.

LGTM

@addaleax
Copy link
Member Author

You can just run any Express app with DEBUG=* and redirect the output to a file, if that works, we are grand with this.

I’ll try that later then. :)

@jasnell
Copy link
Member

jasnell commented Sep 30, 2016

@addaleax ... +1 to exploring if we can fixup instanceof with Duplex separately.
@mcollina and @Fishrock123 ... i definitely think switching to net.Socket later on as a semver-major is the right way to go but we'll have to smoke test that fairly extensively I think. In particular, the fact that socket is a Duplex could throw a few people off given that it would need to be half-closed (e.g. no reading, just writing)

@addaleax
Copy link
Member Author

+1 to exploring if we can fixup instanceof with Duplex separately.

Just in case you haven’t seen it, that would be #8834. :)

@jasnell
Copy link
Member

jasnell commented Sep 30, 2016

ha! yeah, hadn't made it that far through the notifications ;-)

@Fishrock123
Copy link
Contributor

In particular, the fact that socket is a Duplex could throw a few people off given that it would need to be half-closed (e.g. no reading, just writing)

Again, doubtful. My experience so far is that people become confused when stdio is suddenly not sockets when dealing with files.

@mcollina
Copy link
Member

mcollina commented Oct 1, 2016

In particular, the fact that socket is a Duplex could throw a few people off given that it would need to be half-closed (e.g. no reading, just writing)

Again, doubtful. My experience so far is that people become confused when stdio is suddenly not sockets when dealing with files.

I agree with you @Fishrock123. This PR improve things anyway.

@addaleax
Copy link
Member Author

addaleax commented Oct 8, 2016

I’d like to land this on Monday if there are no objections; we can still talk about making SyncWriteStream a proper Socket later.

@Fishrock123 Fishrock123 added this to the v6.8.0 milestone Oct 10, 2016
addaleax added a commit to addaleax/node that referenced this pull request Oct 10, 2016
Make the internal `SyncWriteStream` a proper `stream.Writable`
subclass. This allows for quite a bit of simplification, since
`SyncWriteStream` predates the streams2/streams3 implementations.

Fixes: nodejs#8828
PR-URL: nodejs#8830
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
@addaleax
Copy link
Member Author

Landed in a60f607

@addaleax addaleax closed this Oct 10, 2016
@addaleax addaleax deleted the fs-sws branch October 10, 2016 16:22
jasnell pushed a commit that referenced this pull request Oct 10, 2016
Make the internal `SyncWriteStream` a proper `stream.Writable`
subclass. This allows for quite a bit of simplification, since
`SyncWriteStream` predates the streams2/streams3 implementations.

Fixes: #8828
PR-URL: #8830
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
@Fishrock123
Copy link
Contributor

@addaleax requires internals... think you could backport?

@addaleax
Copy link
Member Author

@Fishrock123 will do :)

addaleax added a commit to addaleax/node that referenced this pull request Oct 11, 2016
Make the internal `SyncWriteStream` a proper `stream.Writable`
subclass. This allows for quite a bit of simplification, since
`SyncWriteStream` predates the streams2/streams3 implementations.

Fixes: nodejs#8828
PR-URL: nodejs#8830
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>
Fishrock123 pushed a commit that referenced this pull request Oct 11, 2016
Make the internal `SyncWriteStream` a proper `stream.Writable`
subclass. This allows for quite a bit of simplification, since
`SyncWriteStream` predates the streams2/streams3 implementations.

Fixes: #8828
PR-URL: #8830
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Jeremiah Senkpiel <[email protected]>

(backport info)
Refs: #9030
Fishrock123 added a commit that referenced this pull request Oct 12, 2016
* fs:
  - `SyncWriteStream` now inherits from `Stream.Writable`. (Anna
Henningsen) #8830
    - Practically, this means that when stdio is piped to a file,
stdout and stderr will still be `Writable` streams.
  - `fs.existsSync()` has been undeprecated. `fs.exists()` remains
deprecated. (Dan Fabulich) #8364
* http: `http.request()` now accepts a `timeout` option. (Rene Weber)
#8101
* module: The module loader now maintains its own realpath cache. (Anna
Henningsen) #8100
* npm: Upgraded to 3.10.8 (Kat Marchán)
#8706
* stream: `Duplex` streams now show proper `instanceof
Stream.Writable`. (Anna Henningsen)
#8834
* timers: Improved `setTimeout`/`Interval` performance by up to 22%.
(Brian White) #8661

PR-URL: #9034
Fishrock123 added a commit that referenced this pull request Oct 12, 2016
* fs:
  - `SyncWriteStream` now inherits from `Stream.Writable`. (Anna
Henningsen) #8830
    - Practically, this means that when stdio is piped to a file,
stdout and stderr will still be `Writable` streams.
  - `fs.existsSync()` has been undeprecated. `fs.exists()` remains
deprecated. (Dan Fabulich) #8364
* http: `http.request()` now accepts a `timeout` option. (Rene Weber)
#8101
* module: The module loader now maintains its own realpath cache. (Anna
Henningsen) #8100
* npm: Upgraded to 3.10.8 (Kat Marchán)
#8706
* stream: `Duplex` streams now show proper `instanceof
Stream.Writable`. (Anna Henningsen)
#8834
* timers: Improved `setTimeout`/`Interval` performance by up to 22%.
(Brian White) #8661

PR-URL: #9034
imyller added a commit to imyller/meta-nodejs that referenced this pull request Oct 13, 2016
    * fs:
      - `SyncWriteStream` now inherits from `Stream.Writable`. (Anna
    Henningsen) nodejs/node#8830
        - Practically, this means that when stdio is piped to a file,
    stdout and stderr will still be `Writable` streams.
      - `fs.existsSync()` has been undeprecated. `fs.exists()` remains
    deprecated. (Dan Fabulich) nodejs/node#8364
    * http: `http.request()` now accepts a `timeout` option. (Rene Weber)
    nodejs/node#8101
    * module: The module loader now maintains its own realpath cache. (Anna
    Henningsen) nodejs/node#8100
    * npm: Upgraded to 3.10.8 (Kat Marchan)
    nodejs/node#8706
    * stream: `Duplex` streams now show proper `instanceof
    Stream.Writable`. (Anna Henningsen)
    nodejs/node#8834
    * timers: Improved `setTimeout`/`Interval` performance by up to 22%.
    (Brian White) nodejs/node#8661

Signed-off-by: Ilkka Myller <[email protected]>
imyller added a commit to imyller/meta-nodejs that referenced this pull request Oct 13, 2016
    * fs:
      - `SyncWriteStream` now inherits from `Stream.Writable`. (Anna
    Henningsen) nodejs/node#8830
        - Practically, this means that when stdio is piped to a file,
    stdout and stderr will still be `Writable` streams.
      - `fs.existsSync()` has been undeprecated. `fs.exists()` remains
    deprecated. (Dan Fabulich) nodejs/node#8364
    * http: `http.request()` now accepts a `timeout` option. (Rene Weber)
    nodejs/node#8101
    * module: The module loader now maintains its own realpath cache. (Anna
    Henningsen) nodejs/node#8100
    * npm: Upgraded to 3.10.8 (Kat Marchan)
    nodejs/node#8706
    * stream: `Duplex` streams now show proper `instanceof
    Stream.Writable`. (Anna Henningsen)
    nodejs/node#8834
    * timers: Improved `setTimeout`/`Interval` performance by up to 22%.
    (Brian White) nodejs/node#8661

Signed-off-by: Ilkka Myller <[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. process Issues and PRs related to the process subsystem. semver-minor PRs that contain new features and should be released in the next minor version. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fs: make process.stdout and stderr descend from Writable.
6 participants