Skip to content
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

Draft: Try to identify the scenario that causes stat throw EINVAL in OSX #57502

Closed
wants to merge 2 commits into from

Conversation

jozkee
Copy link
Member

@jozkee jozkee commented Aug 16, 2021

Related to #57221

@ghost
Copy link

ghost commented Aug 16, 2021

Tagging subscribers to this area: @maryamariyan, @dotnet/area-extensions-filesystem
See info in area-owners.md if you want to be subscribed.

Issue Details

Related to #57221

Author: Jozkee
Assignees: -
Labels:

area-Extensions-FileSystem

Milestone: -

@adamsitnik
Copy link
Member

which syscall gives us an EINVAL?

@jozkee
Copy link
Member Author

jozkee commented Aug 16, 2021

@adamsitnik I suspect is stat since the call-stack in #57221 is related to validation of lstat and stat caches in FileSystem.Unix.cs. However I find it strange since there is no documentation stating that stat is capable of throwing EINVAL. You can look at the conversation I had with Dan for context #57221 (comment). I also find it very strange that it only fails in macOS/OSX.

@danmoseley danmoseley closed this Aug 16, 2021
@danmoseley danmoseley reopened this Aug 16, 2021
@jozkee
Copy link
Member Author

jozkee commented Aug 16, 2021

Based on the latest helix log, I think we can be more certain that the issue is in the stat performed in FileSystemInfo.Refresh().

Unhandled exception. System.IO.IOException: Invalid argument : '/var/folders/4m/hrs4drf17cxbyfbbkbhtxczh0000gy/T/afbguk0e.avl/UsePollingFileWatcher_UseActivePolling_HasChanged_SymbolicLink_TargetDeleted_133_4d15e445'
   at System.IO.FileStatus.ThrowOnCacheInitializationError(ReadOnlySpan`1 path) in /_/src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.Unix.cs:line 418
   at System.IO.FileStatus.GetLastWriteTime(ReadOnlySpan`1 path, Boolean continueOnError) in /_/src/libraries/System.Private.CoreLib/src/System/IO/FileStatus.Unix.cs:line 284
   at System.IO.FileSystemInfo.get_LastWriteTimeUtc() in /_/src/libraries/System.Private.CoreLib/src/System/IO/FileSystemInfo.cs:line 115
   at Microsoft.Extensions.FileProviders.Physical.PollingFileChangeToken.GetLastWriteTimeUtc() in /_/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PollingFileChangeToken.cs:line 61
   at Microsoft.Extensions.FileProviders.Physical.PollingFileChangeToken.get_HasChanged() in /_/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PollingFileChangeToken.cs:line 108
   at Microsoft.Extensions.FileProviders.Physical.PhysicalFilesWatcher.RaiseChangeEvents(Object state) in /_/src/libraries/Microsoft.Extensions.FileProviders.Physical/src/PhysicalFilesWatcher.cs:line 455
   at System.Threading.TimerQueueTimer.Fire(Boolean isThreadPool) in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Timer.cs:line 673
   at System.Threading.TimerQueue.FireNextTimers() in /_/src/libraries/System.Private.CoreLib/src/System/Threading/Timer.cs:line 327

And judging by the filename which shows the test in which is being created (UsePollingFileWatcher_UseActivePolling_HasChanged_SymbolicLink_TargetDeleted_133_4d15e445), it might have something to do with the symlink ceasing to exist between lstat (line 354) and stat (line 365). cc @carlossanlop

internal void RefreshCaches(ReadOnlySpan<char> path)
{
_isDirectory = false;
path = Path.TrimEndingDirectorySeparator(path);
// Retrieve the file cache (lstat) to get the details on the object, without following symlinks.
// If it is a symlink, then subsequently get details on the target of the symlink,
// storing those results separately. We only report failure if the initial
// lstat fails, as a broken symlink should still report info on exists, attributes, etc.
if (!TryRefreshFileCache(path))
{
_exists = false;
return;
}
// Do an initial check in case the main path is pointing to a directory
_isDirectory = CacheHasDirectoryFlag(_fileCache);
// We also need to check if the main path is a symbolic link,
// in which case, we retrieve the symbolic link data
if (!_isDirectory && HasSymbolicLinkFlag && TryRefreshSymbolicLinkCache(path))
{
// and check again if the symlink path is a directory
_isDirectory = CacheHasDirectoryFlag(_symlinkCache);
}

I'm still curious why this happens only on macOS 1014 and 1015, I've stressed calling stat with multiple invalid paths on macOS BigSur 11.5.2 but none has returned me the error "Invalid argument"/EINVAL.

@jozkee
Copy link
Member Author

jozkee commented Aug 17, 2021

Closing as I was finally able to repro locally, see #57221 (comment).

@jozkee jozkee closed this Aug 17, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Sep 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants