Parcourir la source

Fix race condition in rotating file handler, fixes #709

Jordi Boggiano il y a 10 ans
Parent
commit
973d3ca7ae
1 fichiers modifiés avec 4 ajouts et 0 suppressions
  1. 4 0
      src/Monolog/Handler/RotatingFileHandler.php

+ 4 - 0
src/Monolog/Handler/RotatingFileHandler.php

@@ -115,7 +115,11 @@ class RotatingFileHandler extends StreamHandler
 
         foreach (array_slice($logFiles, $this->maxFiles) as $file) {
             if (is_writable($file)) {
+                // suppress errors here as unlink() might fail if two processes
+                // are cleaning up/rotating at the same time
+                set_error_handler(function ($errno, $errstr, $errfile, $errline) {});
                 unlink($file);
+                restore_error_handler();
             }
         }