[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 <pta@odoo.com>
This commit is contained in:
Om Rabara
2023-03-21 19:54:13 +01:00
parent 8580049bf1
commit a06a58e08b
+9 -3
View File
@@ -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