Skip to content

DeduplicationHandler: file handle leak when flock() fails #2025

@ruttydm

Description

@ruttydm

Bug

DeduplicationHandler::collectLogs() opens a file handle on line 145 but never closes it when flock() fails on line 151, leaking a file descriptor.

Version: 3.10.0

Code

DeduplicationHandler.php lines 145–152:

$handle = fopen($this->deduplicationStore, 'rw+');

if (false === $handle) {
    throw new \RuntimeException('Failed to open file for reading and writing: ' . $this->deduplicationStore);
}

if (false === flock($handle, LOCK_EX)) {
    return;  // BUG: $handle is never closed
}

The happy path correctly calls fclose($handle) on line 172, but the early return on line 152 skips it.

Impact

Each failed flock() call leaks one file descriptor. In long-running processes (daemons, queue workers, etc.), this can accumulate and eventually exhaust the OS file descriptor limit.

Suggested fix

if (false === flock($handle, LOCK_EX)) {
    fclose($handle);
    return;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions