PhysicalFilesWatcher: Unhandled Exception: System.IO.IOException
See original GitHub issueDescribe the bug
The (polling) physical file watcher is not protected against possible IO exceptions. In my case I get the following: Unhandled Exception: System.IO.IOException: The process cannot access the file ‘/my/directory’ because it is being used by another process.
Most likely cause is a copy operation that happens on a file that was being watched.
Full Stack Trace
Unhandled Exception: System.IO.IOException: The process cannot access the file ‘/my/directory’ because it is being used by another process.
at System.IO.FileStatus.EnsureStatInitialized(ReadOnlySpan1 path, Boolean continueOnError) at System.IO.FileSystemInfo.Init(FileStatus& fileStatus) at System.IO.FileSystemInfo.Create(String fullPath, String fileName, FileStatus& fileStatus) at System.IO.Enumeration.FileSystemEntry.ToFileSystemInfo() at System.IO.Enumeration.FileSystemEnumerableFactory.<>c.<FileSystemInfos>b__8_0(FileSystemEntry& entry) at System.IO.Enumeration.FileSystemEnumerable
1.DelegateEnumerator.TransformEntry(FileSystemEntry& entry)
at System.IO.Enumeration.FileSystemEnumerator`1.MoveNext()
at Microsoft.Extensions.FileSystemGlobbing.Abstractions.DirectoryInfoWrapper.EnumerateFileSystemInfos()+MoveNext()
at System.Linq.Enumerable.OfTypeIterator[TResult](IEnumerable source)+MoveNext()
at Microsoft.Extensions.FileSystemGlobbing.Internal.MatcherContext.Match(DirectoryInfoBase directory, String parentRelativePath)
at Microsoft.Extensions.FileSystemGlobbing.Internal.MatcherContext.Execute()
at Microsoft.Extensions.FileSystemGlobbing.Matcher.Execute(DirectoryInfoBase directoryInfo)
at Microsoft.Extensions.FileProviders.Physical.PollingWildCardChangeToken.CalculateChanges()
at Microsoft.Extensions.FileProviders.Physical.PollingWildCardChangeToken.get_HasChanged()
at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.RaiseChangeEvents(Object state)
at System.Threading.TimerQueueTimer.CallCallback()
at System.Threading.TimerQueueTimer.Fire()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
Expected behavior
I don’t expect an unhandled exception to occur. I either need to be notified on the registered change callback that this exception occurred or have another way of handling this exception. Alternatively the exception could be ignored as the next polling event will detect the change (when the file is no longer locked by another process).
Additional context
Since this is an unhandled exception in a timer queue thread, my entire aspnet core application crashes and there is no way for me to catch or handle this exception.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6
Top GitHub Comments
Yeah, that’s what I referred to above. It may be that we just add some defensiveness here.
Can you confirm what versions and OS you are using? The output of
dotnet --info
should give all the information we need.@mikaelm12 can you take a look? I presume this is Linux from the path, and occurs if a directory being watched by
PhysicalFilesWatcher
is locked. Should be able to try reproducing this in a simple console app.Might be worth us just catching and logging any
IOException
s that occur in the background timer here. Thoughts @davidfowl ?