Skip to content

fix(imap): do not leak an unhandled error from a pending IDLE task - #302

Merged
robert-virkus merged 1 commit into
Enough-Software:mainfrom
brlumen:fix/imap-idle-unhandled-error
Oct 5, 2026
Merged

robert-virkus merged 1 commit into
Enough-Software:mainfrom
brlumen:fix/imap-idle-unhandled-error

Conversation

@brlumen

@brlumen brlumen commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Fixes #301.

Since #288, disconnect() and connection errors fail every pending task. The IDLE task is sent with returnCompleter: false, so until the IDLE line has been written nobody listens to it and the error is reported as unhandled, e.g. when IDLE waits in the queue behind a pending command. In an isolate with errorsAreFatal: true this terminates the isolate.

idleStart() now marks the task's future as handled; idleDone() and the command queue still receive the result.

Tests

Two cases in test/connection_robustness_test.dart: disconnect() and a lost connection while IDLE waits behind a pending NOOP. Both fail on main with an unhandled ImapException (client disconnected / connection lost: ...) and pass with the fix. dart format and dart test are clean, dart analyze reports no new issues.

disconnect() and connection errors fail every pending task. The IDLE
task is sent with returnCompleter: false, so until the IDLE command has
been written nobody listens to it and the error surfaces as unhandled,
e.g. when IDLE waits in the queue behind a pending command. In an
isolate with errorsAreFatal this terminates the isolate.

Mark the task's future as handled; idleDone() still gets the result.
@robert-virkus

Copy link
Copy Markdown
Member

Love it, thanks!

@robert-virkus
robert-virkus merged commit e8b665a into Enough-Software:main Oct 5, 2026
1 check passed
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.

IMAP: disconnect() or a lost connection raises an unhandled error from an IDLE command that has not been sent yet

2 participants