From a06a58e08bb5d4ae0efd2e702eac85899285a587 Mon Sep 17 00:00:00 2001 From: Om Rabara Date: Fri, 17 Feb 2023 12:30:54 +0000 Subject: [PATCH] [FIX] mail: prevent timed-out error when quit pop and imap server OSError: cannot read from timed out object while evaluating a "model._fetch_mails()", it occurs because when we try to quit a POP server of incoming mail using the "pop_server.quit()" method, sometimes it is not able to reach the remote server to quit the pop server, so it throws an OSError. We added the try block for POP and IMAP. if it fails then we display the os error. sentry-3932133536 closes odoo/odoo#116004 X-original-commit: 0c30529cc9256c0b2483c2fcbbc599b87c1f8577 Signed-off-by: Anh Thao PHAM --- addons/mail/models/fetchmail.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/addons/mail/models/fetchmail.py b/addons/mail/models/fetchmail.py index 25a11b1a940..c3ba19c8ddd 100644 --- a/addons/mail/models/fetchmail.py +++ b/addons/mail/models/fetchmail.py @@ -220,8 +220,11 @@ odoo_mailgate: "|/path/to/odoo-mailgate.py --host=localhost -u %(uid)d -p PASSWO _logger.info("General failure when trying to fetch mail from %s server %s.", server.server_type, server.name, exc_info=True) finally: if imap_server: - imap_server.close() - imap_server.logout() + try: + imap_server.close() + imap_server.logout() + except OSError: + _logger.warning('Failed to properly finish imap connection: %s.', server.name, exc_info=True) elif connection_type == 'pop': try: while True: @@ -251,7 +254,10 @@ odoo_mailgate: "|/path/to/odoo-mailgate.py --host=localhost -u %(uid)d -p PASSWO _logger.info("General failure when trying to fetch mail from %s server %s.", server.server_type, server.name, exc_info=True) finally: if pop_server: - pop_server.quit() + try: + pop_server.quit() + except OSError: + _logger.warning('Failed to properly finish pop connection: %s.', server.name, exc_info=True) server.write({'date': fields.Datetime.now()}) return True