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.Writable reports wrong number in _writableState.bufferedRequestCount #6758

Closed
andrey-makhnutin opened this issue May 14, 2016 · 7 comments
Labels
confirmed-bug Issues with confirmed bugs. good first issue Issues that are suitable for first-time contributors. stream Issues and PRs related to the stream subsystem.

Comments

@andrey-makhnutin
Copy link

  • Version: v6.1.0
  • Platform: Windows 10 64-bit
  • Subsystem: Stream

Was casually reading _stream_writable.js and noticed that clearBuffer() mistakenly zeroes state.bufferedRequestCount at the end of the function in case when _writev is not implemented and _write is not synchronous. The while (entry) loop is breaken from, leaving data in the buffer, but the request counter is zeroed out anyway.

Here's the testing code

'use strict';

const Stream = require('stream');

class testWritable extends Stream.Writable {
  constructor() {
    super({objectMode: true});
  }

  _write(chunk, encoding, cb) {
    console.log(`_writing chunk ${chunk}`);
    setTimeout(cb, 1000);
  }
}

const testStream = new testWritable();

testStream.cork();
for (let i = 1; i <= 5; ++i) {
  testStream.write(i, () => { 
    console.log(`chunk ${i} cb called`);
    console.log(`_writableState.bufferedRequestCount = ${testStream._writableState.bufferedRequestCount}`);
    console.log(`real buffered request count = ${testStream._writableState.getBuffer().length}`);
  });
}
testStream.end();
console.log('main program ends here');

And the output:

_writing chunk 1
main program ends here
_writing chunk 2
chunk 1 cb called
_writableState.bufferedRequestCount = 0
real buffered request count = 3
_writing chunk 3
chunk 2 cb called
_writableState.bufferedRequestCount = 0
real buffered request count = 2
_writing chunk 4
chunk 3 cb called
_writableState.bufferedRequestCount = 0
real buffered request count = 1
_writing chunk 5
chunk 4 cb called
_writableState.bufferedRequestCount = 0
real buffered request count = 0
chunk 5 cb called
_writableState.bufferedRequestCount = 0
real buffered request count = 0

The implications of this are super low, I understand, but you know, just in case.

@vkurchatkin vkurchatkin added the stream Issues and PRs related to the stream subsystem. label May 14, 2016
@Trott
Copy link
Member

Trott commented May 27, 2017

@nodejs/streams

@mcollina mcollina added the confirmed-bug Issues with confirmed bugs. label May 29, 2017
@mcollina
Copy link
Member

@Trott the bug still exists, but it does not have any implication. #6761 had no followup after a review.

Is there anyone that wants to help on this?

@andrey-makhnutin
Copy link
Author

Since I'm the troublemaker here, let me try to give it a go.
I will try to continue and hopefully end #6761 this week

@mcollina
Copy link
Member

@andrey-makhnutin I reopened that PR, if you needed that open.

@BridgeAR BridgeAR added the good first issue Issues that are suitable for first-time contributors. label Sep 23, 2017
@BridgeAR
Copy link
Member

The bug itself is not difficult to fix (have a look at #6761). That PR just needs a test, so it is a awesome good first contribution!

@jlvivero
Copy link
Contributor

jlvivero commented Sep 27, 2017

I'd like to give it a go, this is my first time contributing thought, so It'll take a while to get used to the workflow. It seems the fix itself is already on a pull request (but the pull request is closed), should I make a pull request with the same change but adding tests? Or is the fix wrong and should I also look into how to fix it properly (comment above me suggests it works fine, but I'd like to make sure)

@BridgeAR
Copy link
Member

@jlvivero the fix should be fine as it and it only needs a test. Ideally you could cherry-pick the commit and add a test on top of that or you just do the same change on your own and add a test.

jlvivero added a commit to jlvivero/node that referenced this issue Sep 28, 2017
This changes the disparity of bufferedRequestCount and the actual buffer
on file _stream_writable.js
Fixes: nodejs#6758
MylesBorins pushed a commit that referenced this issue Oct 3, 2017
This changes the disparity of bufferedRequestCount and the actual buffer
on file _stream_writable.js

PR-URL: #15661
Fixes: #6758
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Oct 3, 2017
This changes the disparity of bufferedRequestCount and the actual buffer
on file _stream_writable.js

PR-URL: #15661
Fixes: #6758
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
addaleax pushed a commit to addaleax/ayo that referenced this issue Oct 4, 2017
This changes the disparity of bufferedRequestCount and the actual buffer
on file _stream_writable.js

PR-URL: nodejs/node#15661
Fixes: nodejs/node#6758
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Oct 11, 2017
This changes the disparity of bufferedRequestCount and the actual buffer
on file _stream_writable.js

PR-URL: #15661
Fixes: #6758
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Dec 20, 2017
This changes the disparity of bufferedRequestCount and the actual buffer
on file _stream_writable.js

PR-URL: #15661
Fixes: #6758
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Jan 2, 2018
This changes the disparity of bufferedRequestCount and the actual buffer
on file _stream_writable.js

PR-URL: #15661
Fixes: #6758
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. good first issue Issues that are suitable for first-time contributors. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants