Skip to content
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);