Skip to content

zlib: check if the stream is destroyed before push (8.x) #14396

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

Merged
merged 1 commit into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ Zlib.prototype._processChunk = function _processChunk(chunk, flushFlag, cb) {
if (self._hadError)
return;

if (self.destroyed)
return;

var have = availOutBefore - availOutAfter;
assert(have >= 0, 'have should not go down');

Expand Down
21 changes: 21 additions & 0 deletions test/parallel/test-zlib-destroy-pipe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict';

const common = require('../common');
const zlib = require('zlib');
const { Writable } = require('stream');

// verify that the zlib transform does not error in case
// it is destroyed with data still in flight

const ts = zlib.createGzip();

const ws = new Writable({
write: common.mustCall((chunk, enc, cb) => {
setImmediate(cb);
ts.destroy();
})
});

const buf = Buffer.allocUnsafe(1024 * 1024 * 20);
ts.end(buf);
ts.pipe(ws);