-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
[v13.x] zlib: emits 'close' event after readable 'end' #32215
[v13.x] zlib: emits 'close' event after readable 'end' #32215
Conversation
Call the close method after readable 'end' so that 'close' will be emitted afterwards. Fixes: nodejs#32023 PR-URL: nodejs#32050 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
Seems to fail with the following: ['createDeflate', 'createInflate', true],
['createDeflateRaw', 'createInflateRaw', true],
['createBrotliCompress', 'createBrotliDecompress', true] Maybe related to the "extra data after the compressed data"? |
I think I managed to reduce it to minimal repro: 'use strict';
require('../common');
const zlib = require('zlib');
function createWriter(target, buffer) {
const writer = { size: 0 };
const write = () => {
target.write(Buffer.from([buffer[writer.size++]]), () => {
if (writer.size < buffer.length) {
target.flush(write);
} else {
target.end();
}
});
};
write();
return writer;
}
const compData = Buffer.from('789c4a04000000ffff4a02000000ffff4a06000000ffff4a01000000ffff4a05000000ffff4a03000000ffff4a07000000ffffca00000000ffffca04000000ffffca02000000ffffca06000000ffffca01000000ffffca05000000ffffca03000000ffffca07000000ffff2a00000000ffff2a04000000ffff2a02000000ffff2a06000000ffff2a01000000ffff2a05000000ffff2a03000000ffff2a07000000ffffaa00000000ffffaa04000000ffffaa02000000ffff4a04000000ffff4a02000000ffff4a06000000ffff4a01000000ffff4a05000000ffff4a03000000ffff4a07000000ffffca00000000ffffca04000000ffffca02000000ffffca06000000ffffca01000000ffffca05000000ffffca03000000ffffca07000000ffff2a00000000ffff2a04000000ffff2a02000000ffff2a06000000ffff2a01000000ffff2a05000000ffff2a03000000ffff2a07000000ffffaa00000000ffffaa04000000ffffab02004250163f', 'hex')
const compDataExtra = Buffer.concat([compData, Buffer.from('extra')]);
const decomp = zlib.createInflate();
decomp.resume();
createWriter(decomp, compDataExtra); |
@MylesBorins if 0e89b64 is also included this does not seem to fail. |
Yea sorry, my mistake. Re-applying it basically reverts this commit. |
#32216 seems to resolve it on 13.x. I'm unsure why this doesn't fail on master. |
@@ -274,7 +274,7 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) { | |||
this._defaultFlushFlag = flush; | |||
this._finishFlushFlag = finishFlush; | |||
this._defaultFullFlushFlag = fullFlush; | |||
this.once('end', _close.bind(null, this)); | |||
this.once('end', this.close); |
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.
Instead of doing this, just remove the event listener and enable autoDestroy: true
. Which will ensure the stream is not prematurely destroyed.
@MylesBorins: I would recommend closing this in favor of #32220 and backporting that once it lands. |
Call the close method after readable 'end' so that 'close' will be
emitted afterwards.
Fixes: #32023
PR-URL: #32050
Reviewed-By: Anna Henningsen [email protected]
Reviewed-By: Luigi Pinca [email protected]