coddingtonbear / django-mailbox

Import mail from POP3, IMAP, local email mailboxes or directly from Postfix or Exim4 into your Django application automatically.
MIT License
356 stars 164 forks source link

Close connections after we are done with them #284

Closed akshetpandey closed 6 months ago

akshetpandey commented 6 months ago
Pietro395 commented 6 months ago

Thank you for your contribution @akshetpandey

@pfouque What do you think? do you have an IMAP server in which to test this pull request?

akshetpandey commented 6 months ago

Hi @Pietro395 : This mitigates a production error we noticed when we had a bug in our code. While processing mails, if user code errors out, the connection will remain open on gmail's side until some timeout (or the socket is gc'ed on our side, which should also send a RST). After a few iterations/parallel workers run into this, gmail will start returning:

  File "/layers/google.python.pip/pip/lib/python3.9/site-packages/django_mailbox/transports/imap.py", line 52, in connect
    typ, msg = self.server.login(username, password)
  File "/layers/google.python.runtime/python/lib/python3.9/imaplib.py", line 612, in login
    raise self.error(dat[-1])
imaplib.IMAP4.error: b'[ALERT] Too many simultaneous connections. (Failure)'"