diff --git a/Changes.md b/Changes.md index 3bf33f034..08bcd0229 100644 --- a/Changes.md +++ b/Changes.md @@ -11,6 +11,7 @@ * connection/transaction notes now have get/set #2082 * Fixes * haraka cli will now create folders if they don't exist #2088 + * dkim: prevent dkim_verify from causing 'cannot pipe' #1693 ## 2.8.14 - Jul 26, 2017 diff --git a/dkim.js b/dkim.js index d059524a2..ec6bc88ed 100644 --- a/dkim.js +++ b/dkim.js @@ -473,8 +473,10 @@ DKIMVerifyStream.prototype.handle_buf = function (buf) { self.debug(JSON.stringify(result)); - if (self.pending === 0 && self.cb) { - return self.cb(null, self.result, self.results); + if (self.pending === 0 && self.b) { + return process.nextTick(function () { + self.cb(null, self.result, self.results); + }); } }; @@ -507,7 +509,9 @@ DKIMVerifyStream.prototype.handle_buf = function (buf) { } if (!this.header_idx['dkim-signature']) { this._no_signatures_found = true; - return this.cb(null, this.result, this.results); + return process.nextTick(function () { + self.cb(null, self.result, self.results); + }); } else { // Create new DKIM objects for each header @@ -518,7 +522,9 @@ DKIMVerifyStream.prototype.handle_buf = function (buf) { this.dkim_objects.push(new DKIMObject(dkim_headers[d], this.header_idx, callback, this.timeout)); } if (this.pending === 0) { - if (this.cb) this.cb(new Error('no signatures found')); + process.nextTick(function () { + if (self.cb) self.cb(new Error('no signatures found')); + }); } } continue; // while() @@ -559,7 +565,10 @@ DKIMVerifyStream.prototype.end = function (buf) { this.dkim_objects[d].end(); } if (this.pending === 0 && this._no_signatures_found === false) { - this.cb(null, this.result, this.results); + var self = this; + process.nextTick(function () { + self.cb(null, self.result, self.results); + }); } };