Skip to content

BUG: Debug IMAP file handle leak #504

Description

@andrinoff

Describe the bug

In fetcher/fetcher.go, when the DEBUG_IMAP environment variable is set, a file is opened for debug logging but never closed. Each IMAP connection leaks a file descriptor.

if path := os.Getenv("DEBUG_IMAP"); path != "" {
    if f, err := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600); err == nil {
        options.DebugWriter = f
    }
}

The file f is never closed — there is no defer f.Close() and no tracking of the handle for later cleanup.

To reproduce

  1. Set DEBUG_IMAP=/tmp/imap.log
  2. Run matcha and let it make multiple IMAP connections (e.g. fetch emails, IDLE reconnects)
  3. Observe file descriptor count growing via ls /proc/<pid>/fd | wc -l

Expected behavior

The debug log file handle should be properly closed when the IMAP connection is closed, or a single shared file handle should be reused across connections.

OS

All platforms

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingchoreMaintenance, refactor, cleanup

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions