Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8407086

Browse filesBrowse files
addaleaxtargos
authored andcommitted
zlib: allow writes after readable 'end' to finish
Call the callback for writes that occur after the stream is closed. This also requires changes to the code to not call `.destroy()` on the stream in `.on('end')`, and to ignore chunks written afterwards. Previously, these writes would just queue up silently, as their `_write()` callback would never have been called. Fixes: #30976 PR-URL: #31082 Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 4cd459c commit 8407086
Copy full SHA for 8407086

File tree

Expand file treeCollapse file tree

2 files changed

+21
-8
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-8
lines changed
Open diff view settings
Collapse file

‎lib/zlib.js‎

Copy file name to clipboardExpand all lines: lib/zlib.js
+5-8Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
264264
this._defaultFlushFlag = flush;
265265
this._finishFlushFlag = finishFlush;
266266
this._defaultFullFlushFlag = fullFlush;
267-
this.once('end', this.close);
267+
this.once('end', _close.bind(null, this));
268268
this._info = opts && opts.info;
269269
}
270270
Object.setPrototypeOf(ZlibBase.prototype, Transform.prototype);
@@ -476,7 +476,7 @@ function processChunkSync(self, chunk, flushFlag) {
476476

477477
function processChunk(self, chunk, flushFlag, cb) {
478478
const handle = self._handle;
479-
assert(handle, 'zlib binding closed');
479+
if (!handle) return process.nextTick(cb);
480480

481481
handle.buffer = chunk;
482482
handle.cb = cb;
@@ -502,13 +502,9 @@ function processCallback() {
502502
const self = this[owner_symbol];
503503
const state = self._writeState;
504504

505-
if (self._hadError) {
506-
this.buffer = null;
507-
return;
508-
}
509-
510-
if (self.destroyed) {
505+
if (self._hadError || self.destroyed) {
511506
this.buffer = null;
507+
this.cb();
512508
return;
513509
}
514510

@@ -528,6 +524,7 @@ function processCallback() {
528524
}
529525

530526
if (self.destroyed) {
527+
this.cb();
531528
return;
532529
}
533530

Collapse file
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
const common = require('../common');
3+
const zlib = require('zlib');
4+
5+
// Regression test for https://github.com/nodejs/node/issues/30976
6+
// Writes to a stream should finish even after the readable side has been ended.
7+
8+
const data = zlib.deflateRawSync('Welcome');
9+
10+
const inflate = zlib.createInflateRaw();
11+
12+
inflate.resume();
13+
inflate.write(data, common.mustCall());
14+
inflate.write(Buffer.from([0x00]), common.mustCall());
15+
inflate.write(Buffer.from([0x00]), common.mustCall());
16+
inflate.flush(common.mustCall());

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.