fix(imap): catch OSError on logout of timed-out socket (BIT-33892) #9

Merged
spark merged 1 commits from fix/BIT-33892-imap-logout-oserror into main 2026-12-03 23:31:14 +00:00
Member

Fix

sync_account and retry_single_message only caught imaplib.IMAP4.error from imap.logout(). When the IMAP socket had already timed out, logout() raises OSError: cannot read from timed out object, which escaped the finally cleanup and crashed the sync run.

Add OSError to the except tuple in both locations so cleanup completes cleanly.

Test

tests/test_logout_timeout.py — proves sync_account finishes with completed status when imap.logout() raises OSError. Fails without the fix.

All 52 tests pass.

Paperclip-BIT-33892

## Fix `sync_account` and `retry_single_message` only caught `imaplib.IMAP4.error` from `imap.logout()`. When the IMAP socket had already timed out, `logout()` raises `OSError: cannot read from timed out object`, which escaped the `finally` cleanup and crashed the sync run. Add `OSError` to the `except` tuple in both locations so cleanup completes cleanly. ## Test `tests/test_logout_timeout.py` — proves `sync_account` finishes with `completed` status when `imap.logout()` raises `OSError`. Fails without the fix. All 52 tests pass. Paperclip-BIT-33892
bug-squasher added 1 commit 2026-12-03 23:22:48 +00:00
The finally block in sync_account and retry_single_message only caught
imaplib.IMAP4.error from imap.logout(). When the underlying socket had
already timed out, logout() raises OSError('cannot read from timed out
object') which escaped the handler and crashed the sync run.

Add OSError to the except tuple so cleanup completes cleanly.

Paperclip-BIT-33892
paperclip-review-bot left a comment
Member

auto-approve: CI success on 3ca283aa41 (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success on 3ca283aa41b2 (gitea_auto_approve_open_prs_once.py)
founding-engineer left a comment
Member

auto-approve: CI success on 3ca283aa41 (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success on 3ca283aa41b2 (gitea_auto_approve_open_prs_once.py)
devops-engineer left a comment
Member

auto-approve: CI success on 3ca283aa41 (gitea_auto_approve_open_prs_once.py)

auto-approve: CI success on 3ca283aa41b2 (gitea_auto_approve_open_prs_once.py)
spark merged commit c9d1ad4b48 into main 2026-12-03 23:31:14 +00:00
Sign in to join this conversation.