Skip to content

IMAP lock.release() hangs after fetch #338

@Brandon2255p

Description

@Brandon2255p

Describe the bug
The hang occurs after fetching the email body text after a second lock. Investigation shows that lock.release() in ImapService may not be working correctly, causing the process to hang indefinitely. Need to debug why the mailbox lock is not being released properly after IMAP operations.

The debug test script debug-imap-lock.ts was created to help debug this issue by making two sequential fetches with proper lock handling. Run it with:
npm run debug-imap
This will prompt for password, connect to IMAP, fetch two emails sequentially, and release locks between each operation to help identify where the hang occurs.

To Reproduce
Steps to reproduce the behavior:

  1. Script is attached
  2. Add email in script
  3. npm run debug-imap
  4. Enter password when prompted

Expected behavior
Expected no stacktrace
Expected the lock to release.
Expected the second call to client.fetch to succeed

Desktop (please complete the following information):

  • OS: iOS
  • Node.js v25.2.1

Additional context
Logs of the stacktrace

debug-imap-lock.ts

========== SECOND FETCH ==========
Trace: { msg: 'Requesting lock', path: 'INBOX', lockId: 2, activeLock: null }
    at synteticLogger.<computed> [as trace] (/Users/brandon/Documents/projects/emailsort/node_modules/imapflow/lib/imap-flow.js:3657:46)
    at ImapFlow.getMailboxLock (/Users/brandon/Documents/projects/emailsort/node_modules/imapflow/lib/imap-flow.js:3615:18)
    at main (/Users/brandon/Documents/projects/emailsort/scripts/debug-imap-lock.ts:126:36)
Trace: {
  msg: 'Mailbox lock acquired [existing]',
  path: 'INBOX',
  lockId: 2,
  idling: false
}
    at synteticLogger.<computed> [as trace] (/Users/brandon/Documents/projects/emailsort/node_modules/imapflow/lib/imap-flow.js:3657:46)
    at ImapFlow.processLocks (/Users/brandon/Documents/projects/emailsort/node_modules/imapflow/lib/imap-flow.js:3522:30)
    at /Users/brandon/Documents/projects/emailsort/node_modules/imapflow/lib/imap-flow.js:3630:18
    at new Promise (<anonymous>)
    at ImapFlow.getMailboxLock (/Users/brandon/Documents/projects/emailsort/node_modules/imapflow/lib/imap-flow.js:3628:22)
    at main (/Users/brandon/Documents/projects/emailsort/scripts/debug-imap-lock.ts:126:36)
📧 Lock 2 acquired for second fetch

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions