You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: Debug Toolbar History::setFiles() throws ErrorException on unlink() when concurrent requests prune the same history file #10786
setFiles() runs every time the toolbar data is requested (?debugbar_time=..., via Toolbar::format()). When a page fires several requests at almost the same time (e.g. htmx / fetch calls on an admin dashboard), two PHP-FPM workers can run setFiles() concurrently. Both glob() the same list, both decide the same oldest file is over the limit, the first one deletes it, and the second unlink() fails with a warning. In development the warning is converted to an ErrorException, so it is logged as CRITICAL.
The same code is still in the current develop branch.
Steps to Reproduce
Enable the Debug Toolbar (CI_ENVIRONMENT = development, toolbar filter in after), keep $maxHistory = 20 (default).
Make sure there are already more than 20 files in WRITEPATH/debugbar/.
Open a page that sends several requests in parallel (or open the same page in several tabs at once), so that the toolbar data (?debugbar_time=...) is loaded by multiple PHP-FPM workers at nearly the same moment.
Repeat a few times — occasionally one request logs ErrorException: unlink(...debugbar_*.json): No such file or directory.
It is a race condition, so it does not happen on every request (for us about 1–2 times per day of normal work).
Expected Output
Pruning old history files should be safe under concurrent requests: if the file has already been removed by another request, it should simply be skipped, without a warning / ErrorException.
Anything else?
A possible fix is to ignore files that are already gone, e.g.:
if ($limit >= 0 && $counter > $limit) {
if (is_file($filename)) {
@unlink($filename);
}
continue;
}
(is_file() alone still leaves a small window between the check and unlink(), so suppressing or catching the warning is probably needed as well.)
Related but different: #9504 / #9506 ($maxHistory = 0).
Activity