From 9a4b4cea307afd45576f2a7ffad2b6cd03919a02 Mon Sep 17 00:00:00 2001 From: animetosho Date: Fri, 12 Jan 2024 14:20:20 +1000 Subject: [PATCH] Fix stall that can occur if a connect fails whilst posting Requires post checking to be active, 'connect-fail' error skipping and some working connections Ref #99 --- lib/uploader.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/uploader.js b/lib/uploader.js index ed9f9b0..add1a1a 100644 --- a/lib/uploader.js +++ b/lib/uploader.js @@ -242,28 +242,28 @@ Uploader.prototype = { self.postActive++; c.post(post, function(err, messageId) { self.postActive--; + var postCompletionCb = doPost; if(err) { if(self.cancelled && err.code == 'cancelled') return; dumpPost(self, post); // post.data guaranteed to be set here // handle error skipping err.skippable = true; + var isPostFailure = (['connect_fail','connection_ended','not_connected'].indexOf(err.code) == -1); if(messageId) { if(err.code == 'timeout' && self.skipErrs['post-timeout']) { self._markPostError(post, 'Posting timed out'); } else if((err.code == 'post_denied' || err.code == 'bad_response' || err.code == 'unknown_error') && self.skipErrs['post-reject']) { self._markPostError(post, 'Post rejected (' + err.message + ')'); - } else if(err.code == 'connection_ended' || err.code == 'not_connected') { // internal error - cannot continue - return doPost(err); - } else if(self.skipErrs['post-fail'] && err.code != 'connect_fail') { + } else if(self.skipErrs['post-fail'] && isPostFailure) { self._markPostError(post, 'Posting failed (' + err.message + ')'); } else - return doPost(err); - } else if(self.skipErrs['post-fail'] && ['connect_fail','connection_ended','not_connected'].indexOf(err.code) == -1) { + postCompletionCb = doPost.bind(null, err); + } else if(self.skipErrs['post-fail'] && isPostFailure) { post.messageId = null; // skipping post where Message-ID is completely invalid self._markPostError(post, 'Posting failed (' + err.message + ')'); } else - return doPost(err); + postCompletionCb = doPost.bind(null, err); } self.articlesPosted++; self.bytesPosted += post.inputLen; @@ -286,7 +286,7 @@ Uploader.prototype = { return; } else { post.successful = !err; - self._postComplete(post, err, doPost); + self._postComplete(post, err, postCompletionCb); } }); });