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 } } }