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

stream: Correct bufferedRequestCount in writes #6761

Closed
wants to merge 1 commit into from

Conversation

ngsankha
Copy link

Checklist
  • tests and code linting passes
  • a test and/or benchmark is included
  • documentation is changed or added
  • the commit message follows commit guidelines
Affected core subsystem(s)

stream

Description of change

_writableState.bufferedRequestCount now gives the correct value if the _write is asynchronous. Fixes #6758.

@nodejs-github-bot nodejs-github-bot added the stream Issues and PRs related to the stream subsystem. label May 14, 2016
@mscdex
Copy link
Contributor

mscdex commented May 14, 2016

/cc @nodejs/streams

@calvinmetcalf
Copy link
Contributor

new test please that will fail before the change and not after

@calvinmetcalf
Copy link
Contributor

you can likely adapt the test from #6758

@mcollina
Copy link
Member

First of all, the "bug" is harmless as bufferedWriteCount is used only to increase the throughput of _writev, and that value is completely useless when _writev is not present. The count is actually accurate when _writev is present, because the affected branch in clearBuffer is executed only when there is a single element in the buffer. Things are done this way to save a couple of CPU cycles, maybe with negligible performance impact. This is probably not explained well in https://github.com/nodejs/node/blob/master/lib/_stream_writable.js#L112-L113 (my bad), feel free to add a more explanatory comment there.

This might cause a bug if _writev is added during the life of a stream, but that's probably a mad use case.

I'm generally 👍, pending a comparative benchmark analysis, as clearBuffer is probably one of the hottest function in core. I am confident this will turn out to be ok, but let's check.

Some more considerations:

  1. as far as I know, _writableState is not part of the supported API
  2. I do not think we have any tests testing _writableState or _readableState, and I am not 100% sure we should if we do not put those in the public API
  3. I think we should put part of _writableState and _readableState in the public API, and they should be tested as well.

@rvagg rvagg force-pushed the master branch 2 times, most recently from c133999 to 83c7a88 Compare October 18, 2016 17:01
@mcollina
Copy link
Member

@sankha93 any updates on this? This would need a test.

cc @italoacasas

@mcollina mcollina added the stalled Issues and PRs that are stalled. label Jan 17, 2017
@fhinkel
Copy link
Member

fhinkel commented May 26, 2017

There hasn't been any activity here. I'm closing this. Feel free to reopen (or ping a collaborator) if I closed this in error.

@jasnell
Copy link
Member

jasnell commented Aug 24, 2017

ping @mcollina ... what's the status on this?

@mcollina
Copy link
Member

@jasnell It seems @sankha93 is not committed to adding a test. I'll edit his commit and include one in a new PR. I'll close this when I file the new one.

@BridgeAR
Copy link
Member

Ping @mcollina

@mcollina
Copy link
Member

@BridgeAR I'm a bit busy atm. If someone else would like to take care of this, it would be fantastic.

@BridgeAR
Copy link
Member

I am closing this due to the long inactivity and add a good first contribution label on the bug issue.

@sankha93 thanks a lot for your contribution. Your work is much appreciated nevertheless. If you would like to pursue this further, please leave a comment or open a new PR.

@BridgeAR BridgeAR closed this Sep 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stalled Issues and PRs that are stalled. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants