Errors in Sitecore Cleanup Agent


Description

By default, Sitecore Cleanup Agent is automatically executed every 6 hours to maintain the file system by removing outdated Sitecore files, such as obsolete media cache or log files. When having insufficient permissions to remove the necessary files, Sitecore Cleanup Agent will fail with an error. This article describes various associated errors, their possible culprits, as well as solutions to these errors.

Error 1

Message:

ERROR Exception in Scheduling.CleanupAgent. Folder: <folder path>
Exception: System.UnauthorizedAccessException
Message: Access to the path '<folder path>' is denied.
Source: mscorlib
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileSystemEnumerableIterator`1.CommonInit()
   at System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost)
   at System.IO.DirectoryInfo.InternalGetFiles(String searchPattern, SearchOption searchOption)
   at Sitecore.Tasks.FileCleaner.GetCandidateFiles(DirectoryInfo folder)    at Sitecore.Tasks.FileCleaner.SimpleCleanup(DirectoryInfo folder)    at Sitecore.Tasks.FileCleaner.SimpleCleanup(DirectoryInfo folder, Boolean recursive)    at Sitecore.Tasks.CleanupAgent.Run()

Solution:

Allow the Read/Write/Delete security rights on the folder mentioned in the error message for the App pool Identity used by the website.

Error 2

Message:
INFO  File is being deleted by cleanup task: Filename: <parent folder>/<file name>, file date: 12/12/2014 3:15:13 PM, age: 00:00:17.9730000 (min age: 00:30:00, max age: 00:00:10). Reason: File is older than max age 00:00:10
ERROR Could not delete candidate file.
Exception: System.UnauthorizedAccessException
Message: Access to the path '<file name>' is denied.
Source: mscorlib
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.FileInfo.Delete()
   at Sitecore.Tasks.FileCleaner.GetCandidateFiles(DirectoryInfo folder)
Solution:

Make sure that the Delete subfolders and files permission on <parent folder> has been granted to the App pool Identity used by the website.

Error 3

Message:

INFO  File is being deleted by cleanup task: Filename: <file name>, file date: 12/11/2014 3:41:44 PM, age: 00:00:22.2540000 (min age: 00:30:00, max age: 00:00:10). Reason: File is older than max age 00:00:10
INFO  File was skipped as it appears to be locked by another process.

Solution:

  1. Check if the read-only attribute of the specified file is false.
  2. Check that the App pool Identity used by the website has the Read/Write/Delete access rights on the specified file.
  3. Wait till the next execution of the cleanup agent as the file may be locked by another process at this time.