Skip to content

Conversation

Copy link

Copilot AI commented Jan 2, 2026

During concurrent requests, FileStorage::gc() was calling filemtime() on files that had been deleted by another process between glob() and usort(), producing Warning: filemtime(): stat failed.

Changes

  • Suppress warnings with @ operator: Use @ operator on filemtime() calls to suppress warnings when files are deleted concurrently by another process, reducing I/O operations compared to checking file_exists() first.
  • Handle false returns: filemtime() returns false when a file doesn't exist, which is treated as 0 for sorting purposes.
  • Filter results: Remove non-existent files after sorting to prevent downstream errors.
  • Test coverage: Added testConcurrentDeletion() that simulates the race by deleting files mid-operation.
// Before
usort($files, static fn (string $a, string $b) => filemtime($b) <=> filemtime($a));
return $files;

// After
usort($files, static function (string $a, string $b): int {
    // Use @ to suppress warnings when files are deleted concurrently by another process
    $mtimeA = @filemtime($a);
    $mtimeB = @filemtime($b);
    // filemtime() returns false if file doesn't exist, treat as 0 for sorting
    return ($mtimeB ?: 0) <=> ($mtimeA ?: 0);
});
return array_filter($files, static fn(string $file): bool => @file_exists($file));
Original prompt

This section details on the original issue you should resolve

<issue_title>«Warning: filemtime(): stat failed» during obsolete files cleanup</issue_title>
<issue_description>### Description

During normal, concurrent requests following error happens:

Warning: filemtime(): stat failed for /app/runtime/debug/2025-12-31/69556c95c3b84796964724/summary.json

/vendor/yiisoft/yii-debug/src/Storage/FileStorage.php in Yiisoft\Yii\Debug\Storage\FileStorage::{closure:Yiisoft\Yii\Debug\Storage\FileStorage::findFilesOrderedByModifiedTime():116} at line 116


111            return [];
112        }
113
114        usort(
115            $files,
116            static fn (string $a, string $b) => filemtime($b) <=> filemtime($a)
117        );
118        return $files;
119    }


/vendor/yiisoft/yii-debug/src/Storage/FileStorage.php in Yiisoft\Yii\Debug\Storage\FileStorage::gc at line 82


77    /**
78     * Removes obsolete data files
79     */
80    private function gc(): void
81    {
82        $summaryFiles = $this->findFilesOrderedByModifiedTime($this->path . '/**/**/summary.json');

Package version

yiisoft/yii-debug: 54c57b5

PHP version

8.4.12</issue_description>

<agent_instructions>Handle this edge case with concurrency.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 6 commits January 2, 2026 12:46
Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
…uce test delay

Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix warning during obsolete files cleanup Fix race condition causing filemtime() warnings during concurrent garbage collection Jan 2, 2026
Copilot AI requested a review from samdark January 2, 2026 12:53
@xepozz
Copy link
Member

xepozz commented Jan 2, 2026

It does lots of I/O, better use @ operator here

@samdark
Copy link
Member

samdark commented Jan 3, 2026

@copilot redo fix by adding @ to silence errors and a comment that explains what case does it solve.

Co-authored-by: samdark <47294+samdark@users.noreply.github.com>
Copy link
Author

Copilot AI commented Jan 3, 2026

@copilot redo fix by adding @ to silence errors and a comment that explains what case does it solve.

Done in commit 7b4e6c7. Changed to use @ operator on filemtime() calls to suppress warnings, added explanatory comments about the concurrent deletion case, and reduced I/O by removing redundant file_exists() checks.

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.

«Warning: filemtime(): stat failed» during obsolete files cleanup

4 participants