ulysses/mcp_servers
Lucas Daniel 34bd8f0491
fix(email): guarantee IMAP conn.logout() on all exception paths (#1530)
Three IMAP connection leaks were recently fixed via try/finally
(#1325, #1330, #1423). This commit applies the same pattern to the
remaining callsites that still used inline logout-only cleanup.

routes/email_helpers.py:
- _fetch_sender_thread_context: conn was uninitialized when the outer
  try/except returned early on connect failure, causing the finally
  block to crash on conn.close()/conn.logout(). Merged the two
  separate try blocks into one and added conn=None guard.
- _pre_retrieve_context: ctx_conn.logout() was inside the loop body
  with no finally, so any exception in the folder/search loop leaked
  the socket. Moved cleanup into a finally block with ctx_conn=None
  guard.

mcp_servers/email_server.py:
- _list_emails: multiple inline conn.logout() calls on early-return
  paths; exception between them leaked the socket. Wrapped in
  try/finally.
- _read_email: same pattern — four separate logout() calls replaced
  by a single finally block.
- _reply_to_email: logout() called before the error check, so an
  exception in conn.select() leaked the socket. Wrapped in
  try/finally.
- _download_attachment: same pattern as _reply_to_email.

Also adds tests/test_imap_leak_fixes.py with 9 regression tests (one
per function/failure-mode) that monkeypatch _imap_connect and assert
conn.logout() is called exactly once even when IMAP operations raise.
2026-06-07 05:09:28 +01:00
..
__init__.py Odysseus v1.0 2026-05-31 23:58:26 +09:00
_common.py fix: shared MCP truncate() crashes on None/non-string tool output (#1605) 2026-06-03 08:35:54 +09:00
email_server.py fix(email): guarantee IMAP conn.logout() on all exception paths (#1530) 2026-06-07 05:09:28 +01:00
image_gen_server.py fix(images): render agent-generated images in chat (#2809) 2026-06-05 13:04:33 +02:00
memory_server.py Memory MCP delete: match exact id, not prefix (#1303) 2026-06-03 11:36:19 +09:00
rag_server.py Fix RAG remove_directory wiping the entire shared collection (#1660) (#1734) 2026-06-03 13:29:51 +09:00