-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: fix backpressure when multiple sync
PR-URL: #19613 Fixes: #19601 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
- Loading branch information
Showing
2 changed files
with
51 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const stream = require('stream'); | ||
|
||
let pushes = 0; | ||
const total = 65500 + 40 * 1024; | ||
const rs = new stream.Readable({ | ||
read: common.mustCall(function() { | ||
if (pushes++ === 10) { | ||
this.push(null); | ||
return; | ||
} | ||
|
||
const length = this._readableState.length; | ||
|
||
// We are at most doing two full runs of _reads | ||
// before stopping, because Readable is greedy | ||
// to keep its buffer full | ||
assert(length <= total); | ||
|
||
this.push(Buffer.alloc(65500)); | ||
for (let i = 0; i < 40; i++) { | ||
this.push(Buffer.alloc(1024)); | ||
} | ||
|
||
// We will be over highWaterMark at this point | ||
// but a new call to _read is scheduled anyway. | ||
}, 11) | ||
}); | ||
|
||
const ws = stream.Writable({ | ||
write: common.mustCall(function(data, enc, cb) { | ||
setImmediate(cb); | ||
}, 41 * 10) | ||
}); | ||
|
||
rs.pipe(ws); |