Skip to content

Commit

Permalink
[fix] Ensure _compress() callback is always called (#1618)
Browse files Browse the repository at this point in the history
Fixes #1617
  • Loading branch information
yosiat authored and lpinca committed Aug 12, 2019
1 parent fa99173 commit 3a695e8
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/permessage-deflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ class PerMessageDeflate {
}

if (this._deflate) {
if (this._deflate[kCallback]) {
this._deflate[kCallback]();
}

this._deflate.close();
this._deflate = null;
}
Expand Down Expand Up @@ -312,7 +316,9 @@ class PerMessageDeflate {
zlibLimiter.push((done) => {
this._compress(data, fin, (err, result) => {
done();
callback(err, result);
if (err || result) {
callback(err, result);
}
});
});
}
Expand Down Expand Up @@ -419,6 +425,8 @@ class PerMessageDeflate {
this._deflate.on('data', deflateOnData);
}

this._deflate[kCallback] = callback;

this._deflate.write(data);
this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
if (!this._deflate) {
Expand All @@ -438,6 +446,12 @@ class PerMessageDeflate {

if (fin) data = data.slice(0, data.length - 4);

//
// Ensure that the callback will not be called again in
// `PerMessageDeflate#cleanup()`.
//
this._deflate[kCallback] = null;

if (fin && this.params[`${endpoint}_no_context_takeover`]) {
this._deflate.close();
this._deflate = null;
Expand Down

0 comments on commit 3a695e8

Please sign in to comment.