Skip to content

Commit

Permalink
Merge pull request #1068 from dex4er/upgrade-tls-with-error
Browse files Browse the repository at this point in the history
smtp-connection: Ignore "end" events because it might be "error" after it
  • Loading branch information
andris9 committed Oct 3, 2019
2 parents 7750e04 + 72bade9 commit 29751e7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/smtp-connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,9 @@ class SMTPConnection extends EventEmitter {
* @event
*/
_onEnd() {
this._destroy();
if (this._socket && !this._socket.destroyed) {
this._socket.destroy()
}
}

/**
Expand Down
5 changes: 2 additions & 3 deletions test/smtp-connection/smtp-connection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ describe('SMTP-Connection Tests', function() {
stream.on('data', function() {});
stream.on('end', callback);
},
logger: false
});

insecureServer = new SMTPServer({
Expand Down Expand Up @@ -214,7 +213,7 @@ describe('SMTP-Connection Tests', function() {
client.on('end', done);
});

it('should receive end after STARTTLS', function(done) {
it('should close connection after STARTTLS', function(done) {
let client = new SMTPConnection({
port: PORT_NUMBER,
logger: false
Expand All @@ -228,7 +227,7 @@ describe('SMTP-Connection Tests', function() {
});

client.on('error', function(err) {
expect(err).to.not.exist;
expect(err.message).to.equal("Connection closed unexpectedly");
});

client.on('end', done);
Expand Down
4 changes: 3 additions & 1 deletion test/smtp-pool/smtp-pool-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ describe('SMTP Pool Tests', function() {
)
},
function(err) {
expect(err).to.not.exist;
if (err) {
expect(err.message).to.equal("Connection closed unexpectedly");
}
callback();
}
);
Expand Down

0 comments on commit 29751e7

Please sign in to comment.