From d5d662bc41f8a4056ce578fd6a2c05abcf16d5ec Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 19 Feb 2020 17:04:42 +0100 Subject: [PATCH] fix ordering error --- src/job.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/job.rs b/src/job.rs index 2e7588c5a..6cd29b1fc 100644 --- a/src/job.rs +++ b/src/job.rs @@ -193,14 +193,24 @@ impl Job { Err(crate::smtp::send::Error::SendError(err)) => { // Remote error, retry later. warn!(context, "SMTP failed to send: {}", err); - smtp.disconnect(); self.pending_error = Some(err.to_string()); + + // if the connection was successfully used more than 60 + // seconds ago, try an immediate reconnect. + let mut res = Status::RetryLater; if let Some(secs) = smtp.secs_since_last_success() { if secs > 60 { - return Status::RetryNow; + info!( + context, + "SMTP connection was stale, triggering immediate reconnect" + ); + res = Status::RetryNow; } } - Status::RetryLater + // this clears last_success info + smtp.disconnect(); + + res } Err(crate::smtp::send::Error::EnvelopeError(err)) => { // Local error, job is invalid, do not retry.