Skip to content

COR-264 - Change the IMAP idle disconnect delay at runtime - #119

Merged
dbezverkhnii merged 2 commits into
spark2from
feature/COR-264-runtime-idle-disconnect-delay
Oct 5, 2026
Merged

dbezverkhnii merged 2 commits into
spark2from
feature/COR-264-runtime-idle-disconnect-delay

Conversation

@dbezverkhnii

@dbezverkhnii dbezverkhnii commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

The core wants to close idle IMAP connections quickly in the background and keep them warm on screen, by switching automaticDisconnectDelay when the app changes mode (COR-246). That knob could not be turned at runtime: the session copied it into a connection once, at creation, in whole seconds, and Swift did not expose it.

  • A connection reads the delay from its session when it arms the idle timer, instead of keeping a copy.
  • The setter is callable from any thread. It restarts every idle timer already running, on the session's dispatch queue, where the pool and the timers live.
  • The delay is a double in C++ and the C API; MCOIMAPSession.automaticDisconnectDelay: TimeInterval in Swift.

The C++ changed, so the Windows prebuilt needs a rebuild for this revision before a tag.

Tests: IMAPAutomaticDisconnectDelayTests. A running timer restarts with a shorter delay, sub-second delays are kept, a command in flight is not cut, a leased connection waits for its release, and concurrent changes settle on the last one. Each one was checked to fail without the matching part of the fix.

🤖 Generated with Claude Code


Note

Medium Risk
Changes IMAP connection lifecycle timing and cross-thread pool updates; incorrect timer restarts could drop idle sockets early or keep them open longer than intended.

Overview
IMAP idle auto-disconnect delay can now be changed at runtime so apps can tighten disconnects in the background and keep connections warm on screen.

Session-owned delay: Connections no longer store their own copy at creation. When the idle timer is armed, they read IMAPAsyncSession::automaticDisconnectDelay(). setAutomaticDisconnectDelay is thread-safe (lock + hop to the session dispatch queue) and walks the pool to restartAutomaticDisconnect on any connection that already has a timer running.

API: Delay type moves from time_t (whole seconds) to double through C++/C bindings; Swift adds automaticDisconnectDelay: TimeInterval on IMAPSession. Per-connection setAutomaticDisconnectDelay is removed in favor of restartAutomaticDisconnect (dispatch-queue only).

Tests: IMAPAutomaticDisconnectDelayTests covers shorter delay restarting an armed timer, sub-second values, in-flight commands not being cut, leased connections waiting for release, and concurrent updates settling on the last value.

Reviewed by Cursor Bugbot for commit 8b68c22. Bugbot is set up for automated code reviews on this repo. Configure here.

A host app wants a long idle delay on screen and a short one in the
background, but the session copied the delay into a connection only
when it created one, and only in whole seconds. A connection now reads
the delay from its session when it arms the idle timer, and a change
restarts every timer already running, on the session's dispatch queue.
The delay is a double, and the Swift session exposes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dbezverkhnii
dbezverkhnii requested a balanced review from Copilot October 3, 2026 15:26
@dbezverkhnii

Copy link
Copy Markdown
Collaborator Author

bugbot run

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Changing automaticDisconnectDelay walks the connection list on the
session's dispatch queue, so it joins operationRunningStateChanged() in
the reason acquire and release belong on that queue. The concurrent
test drops an assertion that held by construction.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dbezverkhnii
dbezverkhnii marked this pull request as ready for review October 5, 2026 21:22
@dbezverkhnii
dbezverkhnii merged commit 5ccc865 into spark2 Oct 5, 2026
9 of 10 checks passed
@dbezverkhnii
dbezverkhnii deleted the feature/COR-264-runtime-idle-disconnect-delay branch October 5, 2026 21:22

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 8b68c22. Configure here.

Comment thread src/async/imap/MCIMAPAsyncConnection.cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants