aioimaplib icon indicating copy to clipboard operation
aioimaplib copied to clipboard

Not all commands use a timeout or can be cancelled

Open jgosmann opened this issue 4 years ago • 1 comments

It seems that not all commands are consistently using the configured timeout, in particular I noticed that for UID only the UID FETCH command gets passed the timeout. Is there a reason for this? (I'm not super familiar with IMAP.)

As a workaround I apply await asyncio.wait_for(..., timeout) manually around the corresponding invocations. However, I noticed that this seems to fail to properly cancel the task. At least in the end I'm left with warnings like this one if timeout occur:

Task was destroyed but it is pending!
task: <Task pending coro=<Command.wait() done, defined at /Users/jgosmann/Library/Caches/pypoetry/virtualenvs/dmarc-metrics-exporter-n4MZO14v-py3.7/lib/python3.7/site-packages/aioimaplib/aioimaplib.py:209> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x103fbb510>()]>>

jgosmann avatar Dec 30 '20 14:12 jgosmann

That's a very good question. I just found the comment for the commit 8766c77cd6e407e6fe8b33add4e8acd6490dde7c :

the timeout had been set at the command level for fetch because it can be long, thus the global API timeout was expiring. It is the same for uid fetch and append.

So I guess that it has been added just because the global timeout was expiring in our server. Your workaround is looking fine. I think that the warning would be the same if the timeout would be set at the command level as there still would be a pending task cancelled.

bamthomas avatar Dec 30 '20 16:12 bamthomas