Skip to content

fix: await IDLE loop in email channel disconnect to prevent resource leak#22

Merged
mcheemaa merged 3 commits intoghostwright:mainfrom
jeffklassen:fix/email-idle-loop-resource-leak
Apr 5, 2026
Merged

fix: await IDLE loop in email channel disconnect to prevent resource leak#22
mcheemaa merged 3 commits intoghostwright:mainfrom
jeffklassen:fix/email-idle-loop-resource-leak

Conversation

@jeffklassen
Copy link
Copy Markdown
Contributor

Summary

  • Track the IDLE loop promise so disconnect() can await it before calling logout()
  • Move connectionState = "disconnected" before the abort so the loop's while condition exits immediately
  • Fix the mock IDLE in tests to respond to AbortSignal, matching real ImapFlow behavior
  • Add two tests: disconnect-awaits-loop and rapid disconnect/reconnect doesn't leak

Without this fix, a quick disconnect() + connect() can spawn a second IDLE loop that competes for the INBOX mailbox lock with the first.

Test plan

  • All 824 tests pass (822 existing + 2 new)
  • Lint clean
  • Manual: connect email channel, disconnect, reconnect rapidly — verify single IDLE loop in logs

jeffklassen and others added 3 commits April 1, 2026 09:02
…leak

startIdleLoop() was fire-and-forget, so disconnect() could return
before the loop released the mailbox lock. A rapid disconnect/reconnect
cycle could spawn concurrent IDLE loops competing for the same lock.

Track the loop promise and await it in disconnect(), and set
connectionState before aborting so the loop exits immediately.
@mcheemaa mcheemaa self-requested a review April 5, 2026 03:46
@mcheemaa mcheemaa merged commit cb857d2 into ghostwright:main Apr 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.

2 participants