| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7842f63 commit ae91ffe
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -502,6 +502,7 @@ function clearBuffer(stream, state) { | |||
| 502 | 502 | corkReq.finish = onCorkedFinish.bind(undefined, corkReq, state); | |
| 503 | 503 | state.corkedRequestsFree = corkReq; | |
| 504 | 504 | } | |
| 505 | + state.bufferedRequestCount = 0; | ||
| 505 | 506 | } else { | |
| 506 | 507 | // Slow case, write chunks one-by-one | |
| 507 | 508 | while (entry) { | |
@@ -512,6 +513,7 @@ function clearBuffer(stream, state) { | |||
| 512 | 513 | ||
| 513 | 514 | doWrite(stream, state, false, len, chunk, encoding, cb); | |
| 514 | 515 | entry = entry.next; | |
| 516 | + state.bufferedRequestCount--; | ||
| 515 | 517 | // if we didn't call the onwrite immediately, then | |
| 516 | 518 | // it means that we need to wait until it does. | |
| 517 | 519 | // also, that means that the chunk and cb are currently | |
@@ -525,7 +527,6 @@ function clearBuffer(stream, state) { | |||
| 525 | 527 | state.lastBufferedRequest = null; | |
| 526 | 528 | } | |
| 527 | 529 | ||
| 528 | - state.bufferedRequestCount = 0; | ||
| 529 | 530 | state.bufferedRequest = entry; | |
| 530 | 531 | state.bufferProcessing = false; | |
| 531 | 532 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,34 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const Stream = require('stream'); | ||
| 4 | + // This test ensures that the _writeableState.bufferedRequestCount and | ||
| 5 | + // the actual buffered request count are the same | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + | ||
| 8 | + class StreamWritable extends Stream.Writable { | ||
| 9 | + constructor() { | ||
| 10 | + super({ objectMode: true }); | ||
| 11 | + } | ||
| 12 | + | ||
| 13 | + // We need a timeout like on the original issue thread | ||
| 14 | + // otherwise the code will never reach our test case | ||
| 15 | + // this means this should go on the sequential folder. | ||
| 16 | + _write(chunk, encoding, cb) { | ||
| 17 | + setTimeout(cb, common.platformTimeout(10)); | ||
| 18 | + } | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + const testStream = new StreamWritable(); | ||
| 22 | + testStream.cork(); | ||
| 23 | + | ||
| 24 | + for (let i = 1; i <= 5; i++) { | ||
| 25 | + testStream.write(i, function() { | ||
| 26 | + assert.strictEqual( | ||
| 27 | + testStream._writableState.bufferedRequestCount, | ||
| 28 | + testStream._writableState.getBuffer().length, | ||
| 29 | + 'bufferedRequestCount variable is different from the actual length of' + | ||
| 30 | + ' the buffer'); | ||
| 31 | + }); | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + testStream.end(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments