Permalink
Browse files

Emit error on unexpected close

  • Loading branch information...
1 parent 219b785 commit 111da1673611b307a4af259efe091a1e5409741b @andris9 committed Feb 25, 2014
Showing with 8 additions and 0 deletions.
  1. +8 −0 lib/client.js
View
@@ -379,6 +379,10 @@ SMTPClient.prototype._onDrain = function(){
* @event
*/
SMTPClient.prototype._onClose = function(){
+ if([this._actionGreeting, this._actionIdle, this.close].indexOf(this._currentAction) < 0){
+ return this._onError(new Error("Connection closed unexpectedly"));
+ }
+
this.stage = "close";
this._destroy();
@@ -517,6 +521,10 @@ SMTPClient.prototype.close = function(){
this.log("Closing connection to the server");
}
var closeMethod = "end";
+
+ // Clear current job
+ this._currentAction = this._actionIdle;
+
if (this.stage === "init") {
// Clear connection timeout timer if other than timeout error occurred
clearTimeout(this._connectionTimeout);

0 comments on commit 111da16

Please sign in to comment.