Skip to content

Commit

Permalink
Treat post_interrupted NNTP error as connection-fatal, since it likel…
Browse files Browse the repository at this point in the history
…y causes a desync

Also clear the drain event plus wait-timer if a response was received before the drain fired
Ref #131
  • Loading branch information
animetosho committed May 29, 2024
1 parent a4a0c40 commit 7a60b95
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/nntp.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ NNTP.prototype = {
if(!rf) {
req = this._requests[0];
rf = req.cb;

if(req.type == 'post-upload' && !req.articleSent) {
this._triggerError('post_interrupted', 'Server sent "' + (code + ' ' + m[2].trim()) + '" response during upload');
return;
}
}

var err, nonFatalError = false;
Expand All @@ -523,12 +528,11 @@ NNTP.prototype = {
} else
err = new NNTPError('bad_response', 'Unexpected response to '+req.type+' (code: ' + code + '): ' + m[2].trim());
}
if(!err && req.type == 'post-upload') {
if(!req.articleSent)
err = new NNTPError('post_interrupted', 'Server sent "' + (code + ' ' + m[2].trim()) + '" response during upload');
else if(this._onDrainListener) { // got a response before the drain event fired; this could be a connection desync, but we'll assume the post arrived successfully, and our handler was just fired too late
this._onDrainListener();
}
if(this._onDrainListener && req.type == 'post-upload') {
// got a response before the drain event fired; this could be a connection desync, but we'll assume the post arrived successfully, and our handler was just fired too late
// req.articleSent is guaranteed to be true here, due to check above
this.socket.emit('drain');
this._clearTimer(); // clear response wait timer, since we have the response already
}
}
}
Expand Down

0 comments on commit 7a60b95

Please sign in to comment.