-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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: use ByteLengthQueuingStrategy when not in object mode #48847
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bc642f1
stream: use BLQS when not in objectMode (fixes #46347)
CGQAQ 4a2071d
stream: fix format
CGQAQ d68f95f
stream: fix format again
CGQAQ aec3501
stream: add test case and format
CGQAQ ea2db5f
other: remove unwanted file
CGQAQ 7da26c5
stream: change comment
CGQAQ a93d0c1
stream: fix wrong stream type in adapters.js
CGQAQ ad1cb8f
stream: format
CGQAQ d662d53
stream: format
CGQAQ ace2966
stream: single quotes
CGQAQ 752229a
stream: use ByteLengthQueuingStrategy when not in object mode (fixes …
CGQAQ e614953
fix test
CGQAQ 26ff010
add hasCrypto check
CGQAQ 6cb8b2f
run make lint-js-fix
CGQAQ File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,62 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
if (!common.hasCrypto) { common.skip('missing crypto'); } | ||
|
||
const { Readable } = require('stream'); | ||
const process = require('process'); | ||
const { randomBytes } = require('crypto'); | ||
const assert = require('assert'); | ||
|
||
// Based on: https://github.com/nodejs/node/issues/46347#issuecomment-1413886707 | ||
// edit: make it cross-platform as /dev/urandom is not available on Windows | ||
{ | ||
let currentMemoryUsage = process.memoryUsage().arrayBuffers; | ||
|
||
// We initialize a stream, but not start consuming it | ||
const randomNodeStream = new Readable({ | ||
read(size) { | ||
randomBytes(size, (err, buffer) => { | ||
if (err) { | ||
// If an error occurs, emit an 'error' event | ||
this.emit('error', err); | ||
return; | ||
} | ||
|
||
// Push the random bytes to the stream | ||
this.push(buffer); | ||
}); | ||
} | ||
}); | ||
// after 2 seconds, it'll get converted to web stream | ||
let randomWebStream; | ||
|
||
// We check memory usage every second | ||
// since it's a stream, it shouldn't be higher than the chunk size | ||
const reportMemoryUsage = () => { | ||
const { arrayBuffers } = process.memoryUsage(); | ||
currentMemoryUsage = arrayBuffers; | ||
|
||
assert(currentMemoryUsage <= 256 * 1024 * 1024); | ||
}; | ||
setInterval(reportMemoryUsage, 1000); | ||
|
||
// after 1 second we use Readable.toWeb | ||
// memory usage should stay pretty much the same since it's still a stream | ||
setTimeout(() => { | ||
randomWebStream = Readable.toWeb(randomNodeStream); | ||
}, 1000); | ||
|
||
// after 2 seconds we start consuming the stream | ||
// memory usage will grow, but the old chunks should be garbage-collected pretty quickly | ||
setTimeout(async () => { | ||
// eslint-disable-next-line no-unused-vars | ||
for await (const _ of randomWebStream) { | ||
// Do nothing, just let the stream flow | ||
} | ||
}, 2000); | ||
|
||
setTimeout(() => { | ||
// Test considered passed if we don't crash | ||
process.exit(0); | ||
}, 5000); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this test could be somewhat flakey? too many timeouts but nonetheless shouldn't be a blocker