Re: Timeout when trying to append a big/long message into a mailbox

Nicolas Le Manchet
 

The interesting thing here is that the timeout occurs on write. It looks like the TCP buffers from you to gmail are full and gmail is not consuming bytes fast enough.

There are a few things you can try to debug:

- The traceback shows that you are using `backports.ssl`, did you try running this code from IMAPClient master using the `ssl` module?
- Did you try raising the timeout to an extremely high value to see if it will eventually work?

By the way, I think we could separate the connect and read/write timeout in IMAPClient, like what `requests` does. Usually you want a short connect timeout but long read/write timeout to accommodate slow servers.

Le 14/09/2017 16:41, maxime.lorant@... a écrit :

I discovered a weird bug, regarding *some* Gmail IMAP accounts...
For some reason, I am trying to append a message I just sent using the
SMTP server (and delete the one automatically set by smtp.gmail.com).
It works fine for fairly simple message, but if timeouts after a
certain message size. I have not been able to determine the size, but
as long as you have an attachment, the timeout is almost always
trigerred... It does happen on several Gmail accounts, so it does not
seem an isolated case...
Did anyone encounter this? The problem does not come from imapclient
but maybe someone has a clue about this... I can't reproduce it on
other IMAP servers.

imap = IMAPClient('imap.gmail.com')
# Assume a oauth2_login call here
imap.append('INBOX', 'Subject: Test\r\n\r\n%s' % ('Test test' *
100)) # Small message body, seems OK (appears in my mailbox
after)
b'[APPENDUID 634670718 26357] (Success)'

imap.append('INBOX', 'Subject: Test\r\n\r\n%s' % ('Test test' *
100000))
Traceback (most recent call last):
File ".../lib/python3.5/site-packages/backports/ssl/core.py", line
201, in _safe_ssl_call
return getattr(sock, call)(*args, **kwargs)
File ".../lib/python3.5/site-packages/OpenSSL/SSL.py", line 1540, in
send
self._raise_ssl_error(self._ssl, result)
File ".../lib/python3.5/site-packages/OpenSSL/SSL.py", line 1433, in
_raise_ssl_error
raise WantWriteError()
OpenSSL.SSL.WantWriteError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".../modules/python3.5.2/lib/python3.5/imaplib.py", line 987,
in _command
self.send(literal)
File ".../lib/python3.5/site-packages/imapclient/tls.py", line 171,
in send
sent = self.sock.send(data)
File ".../lib/python3.5/site-packages/backports/ssl/core.py", line
281, in send
return _safe_ssl_call(False, self._conn, 'send', data, flags)
File ".../lib/python3.5/site-packages/backports/ssl/core.py", line
209, in _safe_ssl_call
raise socket.timeout()
socket.timeout
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File ".../python3.5.2/lib/python3.5/code.py", line 91, in runcode
exec(code, self.locals)
File "", line 1, in
File ".../lib/python3.5/site-packages/imapclient/imapclient.py",
line 1007, in append
unpack=True)
File ".../lib/python3.5/site-packages/imapclient/imapclient.py",
line 1180, in _command_and_check
typ, data = meth(*args)
File ".../python3.5.2/lib/python3.5/imaplib.py", line 387, in append
return self._simple_command(name, mailbox, flags, date_time)
File ".../python3.5.2/lib/python3.5/imaplib.py", line 1180, in
_simple_command
return self._command_complete(name, self._command(name, *args))
File ".../python3.5.2/lib/python3.5/imaplib.py", line 990, in
_command
raise self.abort('socket error: %s' % val)
imaplib.abort: socket error:
Links:
------
[1] https://groups.io/g/imapclient/message/167
[2] https://groups.io/mt/6016437/411003
[3] https://groups.io/g/imapclient/post
[4] https://groups.io/g/imapclient/editsub/411003
[5] https://groups.io/g/imapclient
[6] https://groups.io/static/tos
[7] https://groups.io/g/imapclient/leave/defanged

Join imapclient@groups.io to automatically receive all group messages.