unlink(System_Development.log.10): No such file

dear all,

when i have high traffic on the server i regulary notice error messages like this:

Warning: unlink(…/Data/Logs/System_Development.log.10): No such file or directory in …

so i assume that 2 parallel php-processes try to delete the same logfile (logFilesToKeep has configured to 10)

anything i can do against this behaviour?

happens in neos flow 8.3 and 8.4

ciao
H.

This seems to be an issue in the log rotation (as the entry with the suffix .10 is attempted to be removed)

During log rotation we attempt to use a lock via file_exists but its not an atomic operation how we use it flow-development-collection/Neos.Flow.Log/Classes/Backend/FileBackend.php at 54cea0a2cafb9ee1475ae2fdbc1fd3a1830ddc86 · neos/flow-development-collection · GitHub
file_exists could be true for two processes at the same time in a race condition and both processes would touch the lock file.

Instead we need to use an atomic locking

$lockResource = fopen($this->logFileUrl . '.lock', 'w+');

$exclusiveNonBlockingLockResult = flock($lockResource, LOCK_EX | LOCK_NB);
if ($exclusiveNonBlockingLockResult === false) {
   // someone else is on it
   return;
}

// do something only this process is supossed to do...

if (!flock($setupLockResource, LOCK_UN)) {
    throw new \RuntimeException('failed to release lock');
}

ill prepare a PR for testing

PR for Flow :slight_smile: BUGFIX: Fix race condition during log rotation -> the `.lock` file is not properly locked by mhsdesign · Pull Request #3521 · neos/flow-development-collection · GitHub

1 Like