question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PhysicalFilesWatcher: Unhandled Exception: System.IO.IOException

See original GitHub issue

Describe 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.FileSystemEnumerable1.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:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
analogrelaycommented, Jul 3, 2019

Yeah, that’s what I referred to above. It may be that we just add some defensiveness here.

1reaction
analogrelaycommented, Jun 28, 2019

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 IOExceptions that occur in the background timer here. Thoughts @davidfowl ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.IO.IOException "Function not implemented" in ...
When I start debugging my app in a Linux Docker container, I get the exception when calling CreateHostBuilder(args).Build(). The code is part of ......
Read more >
Unhandled exception. System.IO.IOException: Function not ...
I have pulled the latest squidex docker image on a m1 mac and get the following error on startup. Unhandled exception. System.IO.
Read more >
Docker causing exception in .netcore based image
I am a C# developer which runs Unraid at home. I use docker on Unraid to (for example) run an API so that...
Read more >
One container causing another to fail with file access ...
I'm trying to deploy two containers in a container group - my app container and a mssql container that it depends on.
Read more >
Issues running in Docker what am I missing
docker run --name 'PSU' -it -p 5000:5000 ironmansoftware/universal Unhandled exception. System.IO.IOException: Input/output error at System.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found