Hi all,
I'm seeing strange behavior in an application with a certain filesystem. If across multiple threads (generally 5 or more) in the app, I try to create an identical directory structure between all of them. Some of the threads are throwing an IOException with a messaging that one of the intermediate directories already exists. This seems to only happen if the file system is a network server and if I do NOT have ProcMon tracing running on the Client (App) side, but I can get it to happen if I have ProcMon tracing on the Server side.
The app is using .NET 4.5.2, but I've been able to reproduce it using the latest .NET as well.
E.g. I try call Directory.CreateDirectory with the following path across 5 threads: Y:\asdf\006\0\0\0\0
A typical error I will get is the following: Cannot create "Y:\asdf\006\0" because a file or directory with the same name already exists. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)
at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)
at System.IO.Directory.CreateDirectory(String path)
I've read the source code for Directory.CreateDirectory and the key point seems to be the creation of the stackDir for the intermediate directories: https://referencesource.microsoft.com/#mscorlib/system/io/directory.cs,e3885fef9f6af9de
What I don't get is, reading that code, it looks to me like the ONLY time this function would throw this exception would be if that error code was encountered AND the library looks up the already created directory to see if a.) its a file or b.) it got access denied trying to querying it. Is anyone else available to confirm my analysis of that code?
What's frustrating is that the Directory.CreateDirectory says it won't throw that exception if the directory already exists and I can see that the directory already exists. I can also see, when the filesystem is returning NAME COLLISION, that from the server side, I DO NOT see the app requerying the entry to see if its a directory. That also speaks to potential metadata caching on the client side, but I don't see why that would ever return that its not a directory.
Adam