Skip to content

Avoid crashing in PollingFileWatcher #21544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2020
Merged

Avoid crashing in PollingFileWatcher #21544

merged 1 commit into from
May 6, 2020

Conversation

BrennanConroy
Copy link
Member

@BrennanConroy BrennanConroy commented May 6, 2020

There is a race we haven't observed before where the test could finish and cleanup the temporary files it creates but the PollingFileWatcher is in the middle of scanning for changes.

This change will observe the exception and just not look at that directory during the current poll.

The active test run was aborted. Reason: Test host process crashed : Unhandled exception. System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\runner\AppData\Local\Temp\FileWatcherTests-5a01a8c78ee044dfb358a585c3696b83'.
   at System.IO.Enumeration.FileSystemEnumerator`1.CreateDirectoryHandle(String path, Boolean ignoreNotFound)
   at System.IO.Enumeration.FileSystemEnumerator`1.Init()
   at System.IO.Enumeration.FileSystemEnumerator`1..ctor(String directory, Boolean isNormalized, EnumerationOptions options)
   at System.IO.Enumeration.FileSystemEnumerable`1..ctor(String directory, FindTransform transform, EnumerationOptions options, Boolean isNormalized)
   at System.IO.Enumeration.FileSystemEnumerableFactory.FileSystemInfos(String directory, String expression, EnumerationOptions options, Boolean isNormalized)
   at System.IO.DirectoryInfo.InternalEnumerateInfos(String path, String searchPattern, SearchTarget searchTarget, EnumerationOptions options)
   at Microsoft.DotNet.Watcher.Internal.PollingFileWatcher.ForeachEntityInDirectory(DirectoryInfo dirInfo, Action`1 fileAction) in /_/src/Tools/dotnet-watch/src/Internal/FileWatcher/PollingFileWatcher.cs:line 191
   at Microsoft.DotNet.Watcher.Internal.PollingFileWatcher.CheckForChangedFiles() in /_/src/Tools/dotnet-watch/src/Internal/FileWatcher/PollingFileWatcher.cs:line 105
   at Microsoft.DotNet.Watcher.Internal.PollingFileWatcher.PollingLoop() in /_/src/Tools/dotnet-watch/src/Internal/FileWatcher/PollingFileWatcher.cs:line 85
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ThreadHelper.ThreadStart()

@BrennanConroy BrennanConroy added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label May 6, 2020
// If the directory is deleted after the exists check this will throw and could crash the process
catch (DirectoryNotFoundException)
{
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think the ForeachEntityInDirectory needs a similar treatment vis-a-vis files being deleted?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

? This is in ForeachEntityInDirectory

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so? It has a catch for FileNotFoundException and is using the already resolved FileSystemInfo object, so should be pretty safe.

@Pilchie
Copy link
Member

Pilchie commented May 6, 2020

👀

@Pilchie
Copy link
Member

Pilchie commented May 6, 2020

There are 12 quarantined dotnet-watch tests. Possible that others of them are related to this?

@BrennanConroy
Copy link
Member Author

There are 12 quarantined dotnet-watch tests. Possible that others of them are related to this?

I know I put some of them in quarantine when I enabled them to run on Helix. It's probably time for some of them to leave. I do see that there are a couple semi recent failures, but they don't look related.

@BrennanConroy BrennanConroy merged commit 5fd4f87 into master May 6, 2020
@BrennanConroy BrennanConroy deleted the brecon/watch branch May 6, 2020 22:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants