Fix: catch TimeoutError on per-message IMAP fetch (BIT-33891)
Root cause
sync_account wraps the fetch_message(imap, uid) call in except imaplib.IMAP4.error, but TimeoutError (raised by socket.recv
during a slow IMAP read) is an OSError subclass — not an imaplib.IMAP4.error. The timeout escaped the per-message handler and
hit the outer except Exception, marking the entire sync run as
failed and reporting an Error Loop event for a single slow message.
Fix
src/forwarder/services/sync_service.py:263 — broaden the exception
clause to (imaplib.IMAP4.error, OSError) so a timed-out fetch is
logged, counted as messages_failed, and the sync continues with the
next message.
Test
tests/test_sync_timeout.py — mocks fetch_message to raise TimeoutError for every UID in a folder and asserts:
fetch_message called for both UIDs (sync did not abort)
Verified the test fails on unpatched main (status = failed) and
passes with the fix. Full suite: 52/52 green.
## Fix: catch `TimeoutError` on per-message IMAP fetch (BIT-33891)
### Root cause
`sync_account` wraps the `fetch_message(imap, uid)` call in
`except imaplib.IMAP4.error`, but `TimeoutError` (raised by `socket.recv`
during a slow IMAP read) is an `OSError` subclass — **not** an
`imaplib.IMAP4.error`. The timeout escaped the per-message handler and
hit the outer `except Exception`, marking the **entire sync run as
failed** and reporting an Error Loop event for a single slow message.
### Fix
`src/forwarder/services/sync_service.py:263` — broaden the exception
clause to `(imaplib.IMAP4.error, OSError)` so a timed-out fetch is
logged, counted as `messages_failed`, and the sync continues with the
next message.
### Test
`tests/test_sync_timeout.py` — mocks `fetch_message` to raise
`TimeoutError` for every UID in a folder and asserts:
- `sync_run.status == SyncRunStatus.completed` (not `failed`)
- `sync_run.messages_failed == 2` (both UIDs counted)
- `fetch_message` called for both UIDs (sync did not abort)
Verified the test fails on unpatched `main` (status = `failed`) and
passes with the fix. Full suite: 52/52 green.
TimeoutError (OSError subclass) escaped the imaplib.IMAP4.error handler
in sync_account, killing the entire sync run on a single slow fetch.
Catch OSError alongside IMAP4.error to skip the timed-out message and
continue scanning.
Paperclip-BIT-33891
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Fix: catch
TimeoutErroron per-message IMAP fetch (BIT-33891)Root cause
sync_accountwraps thefetch_message(imap, uid)call inexcept imaplib.IMAP4.error, butTimeoutError(raised bysocket.recvduring a slow IMAP read) is an
OSErrorsubclass — not animaplib.IMAP4.error. The timeout escaped the per-message handler andhit the outer
except Exception, marking the entire sync run asfailed and reporting an Error Loop event for a single slow message.
Fix
src/forwarder/services/sync_service.py:263— broaden the exceptionclause to
(imaplib.IMAP4.error, OSError)so a timed-out fetch islogged, counted as
messages_failed, and the sync continues with thenext message.
Test
tests/test_sync_timeout.py— mocksfetch_messageto raiseTimeoutErrorfor every UID in a folder and asserts:sync_run.status == SyncRunStatus.completed(notfailed)sync_run.messages_failed == 2(both UIDs counted)fetch_messagecalled for both UIDs (sync did not abort)Verified the test fails on unpatched
main(status =failed) andpasses with the fix. Full suite: 52/52 green.
auto-approve: CI success on
66dcd1f78e(gitea_auto_approve_open_prs_once.py)auto-approve: CI success on
66dcd1f78e(gitea_auto_approve_open_prs_once.py)auto-approve: CI success on
66dcd1f78e(gitea_auto_approve_open_prs_once.py)