-
-
Notifications
You must be signed in to change notification settings - Fork 36.7k
zlib: do not coalesce multiple .flush() calls
#28520
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Next
Next commit
zlib: do not coalesce multiple
.flush() calls
This is an approach to address the issue linked below. Previously, when `.write()` and `.flush()` calls to a zlib stream were interleaved synchronously (i.e. without waiting for these operations to finish), multiple flush calls would have been coalesced into a single flushing operation. This patch changes behaviour so that each `.flush()` all corresponds to one flushing operation on the underlying zlib resource, and the order of operations is as if the `.flush()` call were a `.write()` call. One test had to be removed because it specifically tested the previous behaviour. As a drive-by fix, this also makes sure that all flush callbacks are called. Previously, that was not the case. Fixes: #28478
- Loading branch information
commit 5e592d2ba0cfde75d1c6f8e6a39eace76cc18197
There are no files selected for viewing
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 { createGzip, createGunzip, Z_PARTIAL_FLUSH } = require('zlib'); | ||
|
|
||
| // Verify that .flush() behaves like .write() in terms of ordering, e.g. in | ||
| // a sequence like .write() + .flush() + .write() + .flush() each .flush() call | ||
| // only affects the data written before it. | ||
| // Refs: https://github.com/nodejs/node/issues/28478 | ||
|
|
||
| const compress = createGzip(); | ||
| const decompress = createGunzip(); | ||
| decompress.setEncoding('utf8'); | ||
|
|
||
| const events = []; | ||
|
|
||
| for (const chunk of ['abc', 'def', 'ghi']) { | ||
| compress.write(chunk, common.mustCall(() => events.push({ written: chunk }))); | ||
| compress.flush(Z_PARTIAL_FLUSH, common.mustCall(() => { | ||
| events.push('flushed'); | ||
| decompress.write(compress.read(), common.mustCall(() => { | ||
| events.push({ read: decompress.read() }); | ||
| })); | ||
| })); | ||
| } | ||
|
|
||
| process.on('exit', () => { | ||
| assert.deepStrictEqual(events, [ | ||
| { written: 'abc' }, | ||
| 'flushed', | ||
| { written: 'def' }, | ||
| { read: 'abc' }, | ||
| 'flushed', | ||
| { written: 'ghi' }, | ||
| { read: 'def' }, | ||
| 'flushed', | ||
| { read: 'ghi' } | ||
| ]); | ||
| }); | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.