Skip to content

Commit

Permalink
Merge pull request #632 from darrachequesne/patch-2
Browse files Browse the repository at this point in the history
Fix "zlib binding closed" errors
  • Loading branch information
3rd-Eden committed Dec 21, 2015
2 parents fddc914 + 4bf5fb8 commit 4423b6e
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/PerMessageDeflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,20 @@ PerMessageDeflate.prototype.accept = function(paramsList) {

PerMessageDeflate.prototype.cleanup = function() {
if (this._inflate) {
if (this._inflate.close) this._inflate.close();
this._inflate = null;
if (this._inflate.writeInProgress) {
this._inflate.pendingClose = true;
} else {
if (this._inflate.close) this._inflate.close();
this._inflate = null;
}
}
if (this._deflate) {
if (this._deflate.close) this._deflate.close();
this._deflate = null;
if (this._deflate.writeInProgress) {
this._deflate.pendingClose = true;
} else {
if (this._deflate.close) this._deflate.close();
this._deflate = null;
}
}
};

Expand Down Expand Up @@ -224,6 +232,7 @@ PerMessageDeflate.prototype.decompress = function (data, fin, callback) {
windowBits: 'number' === typeof maxWindowBits ? maxWindowBits : DEFAULT_WINDOW_BITS
});
}
this._inflate.writeInProgress = true;

var self = this;
var buffers = [];
Expand Down Expand Up @@ -251,7 +260,8 @@ PerMessageDeflate.prototype.decompress = function (data, fin, callback) {
if (!self._inflate) return;
self._inflate.removeListener('error', onError);
self._inflate.removeListener('data', onData);
if (fin && self.params[endpoint + '_no_context_takeover']) {
self._inflate.writeInProgress = false;
if ((fin && self.params[endpoint + '_no_context_takeover']) || self._inflate.pendingClose) {
if (self._inflate.close) self._inflate.close();
self._inflate = null;
}
Expand All @@ -275,6 +285,7 @@ PerMessageDeflate.prototype.compress = function (data, fin, callback) {
memLevel: this._options.memLevel || DEFAULT_MEM_LEVEL
});
}
this._deflate.writeInProgress = true;

var self = this;
var buffers = [];
Expand Down Expand Up @@ -303,7 +314,8 @@ PerMessageDeflate.prototype.compress = function (data, fin, callback) {
if (!self._deflate) return;
self._deflate.removeListener('error', onError);
self._deflate.removeListener('data', onData);
if (fin && self.params[endpoint + '_no_context_takeover']) {
self._deflate.writeInProgress = false;
if ((fin && self.params[endpoint + '_no_context_takeover']) || self._deflate.pendingClose) {
if (self._deflate.close) self._deflate.close();
self._deflate = null;
}
Expand Down

0 comments on commit 4423b6e

Please sign in to comment.