Skip to content

singleton.py: File descriptor leaks when flock raises non-BlockingIOError #59

Description

@brandwe

File: src/entrabot/singleton.py
Location: L174-L185 (acquire_singleton_lock)
Category: leak
Priority: low

Description

fd = os.open(...) succeeds, then fcntl.flock(fd, ...) is wrapped in a try that catches only BlockingIOError. Any other OSError (EINTR, EPERM, ENOLCK on a network mount, EIO) propagates with fd still open. Acquisition runs once per process so impact is small, but tests, restart loops, and a future Windows replacement will inherit the pattern; lock file mode 0600 makes the leak slightly more visible to auditors.

Suggested fix

Use try/except OSError (or try/finally) that closes the fd before re-raising anything other than BlockingIOError.


Filed automatically by a thorough code-review pass over src/entrabot/ on 2026-06-13. Internal review id: #35.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions