dokan-dev / dokan-dotnet

Dokan DotNet Wrapper
http://dokan-dev.github.io
MIT License
462 stars 116 forks source link

SharingViolation exception in CreateFile (it is called in many times in one behavior) #258

Closed NavigatorXia closed 4 years ago

NavigatorXia commented 4 years ago

Today I got an interest problem. (In Dokan-Dotnet Sample Mirror.cs)

As we know, if a new file need to be created, in CreateFile, the following code will create it. info.Context = new FileStream(fileName, mode, readAccess ? System.IO.FileAccess.Read : System.IO.FileAccess.ReadWrite, share, options); Parameters: readAccess is false, mode is Create. When I set break point to track it, I found CreateFile will enter many times with same parameter. The new FileStream hasn't finish its work(no file created in disk), but the next CreateFile is called. And which will leads SharingViolation exception, and I noticed they shared one same IDokanFileInfo.ProcessID.

Liryna commented 4 years ago

Hi!

An application can call CreateFile multiple times with the same parameters. Each of the calls will have a different context and FileStream.

There is a known problem that might only be from the mirror sample that looks to be a race condition I haven't had the time to look at https://ci.appveyor.com/project/Liryna/dokan-dotnet/build/job/vj57mk0qce90dmsa#L253

The test exactly fail as you said. Do you think you would have the possibility to look at it?

Here is how the test are runned https://github.com/dokan-dev/dokan-dotnet/blob/master/appveyor.yml#L70-L95

You can remove from the t directory all other test to have only 09_CreateFile_Sharing test

NavigatorXia commented 4 years ago

It has a trick behavior in my two machines, one has SharingViolation problem, the other has not.

the other one may lead error like: "The process cannot access the file 'xxx.xxx' because it is being used by another process" but no SharingViolation exception

Liryna commented 4 years ago

@NavigatorXia This depends on how to app display the error. You can use procmon to track the process activity and see exactly what happens

NavigatorXia commented 4 years ago

One more question: how to use these data member in IDokanFileInfo, such as NoCache,PagingIo,ProcessId、 SynchronousIo,WriteToEndOfFile

I notice the Mirror doesn't use them in read/wirte operation.

Liryna commented 4 years ago

@NavigatorXia You can find the document website on the Readme or the Readme of dokany that is more detailed on the work flow.