fix: clean up the IMAP object on a failed connect; module-level asyncio import
on a failed connect attempt the IMAP4 object was dropped without logout(), leaking the socket aioimaplib held; now it is logged out (best-effort) before nulling. also moved the asyncio import in oauth.py from inside the retry loop to module top. Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
parent
ba7ae48a87
commit
7934688595
@ -11,16 +11,16 @@ This reads codes from email; it does not generate them (that is `pyotp`'s job).
|
|||||||
`requirements.txt`:
|
`requirements.txt`:
|
||||||
|
|
||||||
```
|
```
|
||||||
aiomail @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.0
|
aiomail @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.1
|
||||||
# OAuth token providers (Microsoft / Google) need the extra:
|
# OAuth token providers (Microsoft / Google) need the extra:
|
||||||
aiomail[oauth] @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.0
|
aiomail[oauth] @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.1
|
||||||
```
|
```
|
||||||
|
|
||||||
Direct:
|
Direct:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pip install "aiomail @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.0"
|
pip install "aiomail @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.1"
|
||||||
pip install "aiomail[oauth] @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.0"
|
pip install "aiomail[oauth] @ git+ssh://git@git.rethinkstudios.io/rethink-public/aiomail.git@v0.1.1"
|
||||||
```
|
```
|
||||||
|
|
||||||
Requires `aioimaplib` and `beautifulsoup4` (pulled transitively). The `oauth`
|
Requires `aioimaplib` and `beautifulsoup4` (pulled transitively). The `oauth`
|
||||||
|
|||||||
@ -67,6 +67,11 @@ class IMAPClient:
|
|||||||
return True
|
return True
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
log.warning("connect attempt %d/%d failed: %s", attempt + 1, self.max_retries, exc)
|
log.warning("connect attempt %d/%d failed: %s", attempt + 1, self.max_retries, exc)
|
||||||
|
if self._mail is not None:
|
||||||
|
try:
|
||||||
|
await self._mail.logout()
|
||||||
|
except Exception as teardown:
|
||||||
|
log.debug("logout error ignored during failed connect: %s", teardown)
|
||||||
self._mail = None
|
self._mail = None
|
||||||
await asyncio.sleep(2 * (attempt + 1))
|
await asyncio.sleep(2 * (attempt + 1))
|
||||||
return False
|
return False
|
||||||
|
|||||||
@ -6,6 +6,7 @@ without aiohttp raises a clear error only when a provider is instantiated.
|
|||||||
|
|
||||||
credentials (client_id, refresh_token) are always supplied by the caller.
|
credentials (client_id, refresh_token) are always supplied by the caller.
|
||||||
"""
|
"""
|
||||||
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
from typing import Optional, Sequence
|
from typing import Optional, Sequence
|
||||||
@ -85,8 +86,6 @@ class _RefreshTokenProvider:
|
|||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
log.warning("token request to %s failed: %s", endpoint, exc)
|
log.warning("token request to %s failed: %s", endpoint, exc)
|
||||||
if attempt < self.max_retries - 1:
|
if attempt < self.max_retries - 1:
|
||||||
import asyncio
|
|
||||||
|
|
||||||
await asyncio.sleep(2 ** attempt)
|
await asyncio.sleep(2 ** attempt)
|
||||||
|
|
||||||
self._failures += 1
|
self._failures += 1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user