From 7a60b9559c6b7cd43cdff8aa3bcadf3061646968 Mon Sep 17 00:00:00 2001 From: animetosho Date: Wed, 29 May 2024 22:11:18 +1000 Subject: [PATCH] Treat post_interrupted NNTP error as connection-fatal, since it likely causes a desync Also clear the drain event plus wait-timer if a response was received before the drain fired Ref #131 --- lib/nntp.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/nntp.js b/lib/nntp.js index 1a1ecc5..a7531fc 100644 --- a/lib/nntp.js +++ b/lib/nntp.js @@ -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; @@ -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 } } }