Skip to content

Commit

Permalink
Fix NNTP client connecting if destroyed before connect attempt made
Browse files Browse the repository at this point in the history
  • Loading branch information
animetosho committed May 31, 2022
1 parent fb3627b commit 3d31f97
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/nntp.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ NNTP.prototype = {
var self = this;
async.waterfall([
function(cb) {
if(self._finished) return cb(null, null, null); // maybe happens if .destroy called immediately after connect?
self._respFunc = cb;
self.socket = self.connectSocket(function(err) {
if(!err) return;
Expand Down
5 changes: 4 additions & 1 deletion test/nntp.js
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,7 @@ it('should call all end/close callbacks when closed');

it('should not connect if destroyed straight after', function(done) {
var server, client;
var cancelled = false;
waterfall([
killServer,
function(cb) {
Expand All @@ -656,12 +657,14 @@ it('should not connect if destroyed straight after', function(done) {
client = _client;
client.connect(function(err) {
assert.equal(err.code, 'cancelled');
cb();
cancelled = true;
});
client.destroy();
tl.defer(cb);
},
function(cb) {
assert.equal(client.state, 'inactive');
assert(cancelled);
closeTest(client, server, cb);
}
], done);
Expand Down

0 comments on commit 3d31f97

Please sign in to comment.