From 18b3658b3bbe980ed444a80af63b09e1718ff80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arno=20T=C3=B6ll?= Date: Sun, 26 Feb 2012 12:01:11 -0500 Subject: [PATCH] Do not crash if the server closes the connection after the first iteration Handle reconnects softly --- debexpo/cronjobs/removeolduploads.py | 1 + debexpo/lib/email.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/debexpo/cronjobs/removeolduploads.py b/debexpo/cronjobs/removeolduploads.py index c310a300..3e1888ff 100644 --- a/debexpo/cronjobs/removeolduploads.py +++ b/debexpo/cronjobs/removeolduploads.py @@ -100,6 +100,7 @@ class RemoveOldUploads(BaseCronjob): self.log.debug("Processed all messages up to #%s on %s" % (list_name.value, list_name.code)) meta.session.merge(list_name) meta.session.commit() + self.mailer.disconnect_from_server() def _remove_old_packages(self): now = datetime.datetime.now() diff --git a/debexpo/lib/email.py b/debexpo/lib/email.py index 55522700..88bcb9ef 100644 --- a/debexpo/lib/email.py +++ b/debexpo/lib/email.py @@ -140,8 +140,13 @@ class Email(object): (_, count, first, last, _) = self.nntp.group(list_name) log.debug("Fetching messages %s to %s on %s" % (changed_since, last, list_name)) except nntplib.NNTPError as e: + self.established = False log.error("Connecting to NNTP server %s failed: %s" % (pylons.config['debexpo.nntp_server'], str(e))) return + except EOFError: + self.established = False + log.error("NNTP server %s closed connection" % (pylons.config['debexpo.nntp_server'])) + return try: (_, messages) = self.nntp.xover(str(changed_since), str(last)) @@ -168,11 +173,13 @@ class Email(object): def disconnect_from_server(self): self.nntp.quit() - + self.established = False def connection_established(self): if not self.established: - log.debug("Connection to NNTP server not established"); - return False + self.connect_to_server() + if not self.established: + log.debug("Connection to NNTP server not established"); + return self.established return True -- GitLab