Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions lib/permessage-deflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,14 @@ function inflateOnData(chunk) {
this[kError].code = 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH';
this[kError][kStatusCode] = 1009;
this.removeListener('data', inflateOnData);

//
// The choice to employ `zlib.reset()` over `zlib.close()` is dictated by the
// fact that in Node.js versions prior to 13.10.0, the callback for
// `zlib.flush()` is not called if `zlib.close()` is used. Utilizing
// `zlib.reset()` ensures that either the callback is invoked or an error is
// emitted.
//
this.reset();
}

Expand All @@ -509,6 +517,12 @@ function inflateOnError(err) {
// closed when an error is emitted.
//
this[kPerMessageDeflate]._inflate = null;

if (this[kError]) {
this[kCallback](this[kError]);
return;
}

err[kStatusCode] = 1007;
this[kCallback](err);
}
2 changes: 1 addition & 1 deletion test/permessage-deflate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ describe('PerMessageDeflate', () => {

it("doesn't call the callback twice when `maxPayload` is exceeded", (done) => {
const perMessageDeflate = new PerMessageDeflate({}, false, 25);
const buf = Buffer.from('A'.repeat(50));
const buf = Buffer.from('A'.repeat(1024 * 1024));

perMessageDeflate.accept([{}]);
perMessageDeflate.compress(buf, true, (err, data) => {
Expand Down