dokan-dev / dokan-dotnet

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

Word file EDIT issue (when Read , Write takes a bit long) #314

Closed MagaKhachatryan closed 2 years ago

MagaKhachatryan commented 2 years ago

In the attached project we have a class named NewFileStream in which Read and Write operations are changed to last a bit longer by adding Thread.Sleep(50) and in this case we are unable to save our changes in Word file by pressing CTRL+S. We try to imitate the encryption/decryption processes that we have in our actual project. As we found out that the problem is just the time that encryption/decryption takes we did it like this. The change is made on the sample downloaded from your git repo. You can try to reproduce the issue with the attached word file.

Drive.zip

Encryption research.docx

Liryna commented 2 years ago

Hi @MagaKhachatryan ,

Could you describe exactly what Word error is showing ? Have you looked at the procmon output to see what is exactly happening between word and the file ?

MagaKhachatryan commented 2 years ago

HI @Liryna , Thanks for your response. The problem is that Word is not showing any errors, it just doesn't save the file. So when we edit something on Word file , then try to save it by pressing CTRL+S , "Saved to this PC" doesn't appear on the top of the file, so if we try to close the file after this it asks us if we want to save it. And about Process Monitor , we tried to look at it's output , but when Process Monitor is working the save operation works correctly, but just after closing it, save stops working again. Here is the recording, so you can see what is going on.

https://user-images.githubusercontent.com/48995007/181494093-cfa23b42-9214-4f64-8a8d-7f69562002fc.mp4

P.S. We are able to reproduce the issue on the original sample itself, it just happens more rarely (once from 7-10 tries). Making read/write longer makes it to happen once of 3-4 tries.

Liryna commented 2 years ago

If there is nothing special in the Dokan logs and Procmon cannot record the failure, that's not going to be easy to resolve. How much threads are used by the Dokan library ? Do you think there is a request hanging ?

MagaKhachatryan commented 2 years ago

Yes, it's not an easy case, it took much time to me to understand what's going. If we do these steps while Procmon is working the issue doesn't happen, so in fact in this case there is no failure to record. This is kind of interesting. How Procmon affects the saving operation? It is a third party tool which aim is to give us information about processes, isn't it? Thread count of Dokan library is 25.

The attached zip file is a clear reproduction of the issue, if you will have a chance to run it, it would be more clear I think.

Liryna commented 2 years ago

This is kind of interesting. How Procmon affects the saving operation? It is a third party tool which aim is to give us information about processes, isn't it?

Yes, it shows what are the Word IO and possibly on which one it is waiting for during the save.

Thread count of Dokan library is 25.

The max number of thread is 16 https://github.com/dokan-dev/dokany/blob/a04b410e692c08a1143c901e8265751c89a70819/dokan/dokan_pool.h#L28 You can look at the logs to see how much are used https://github.com/dokan-dev/dokany/blob/master/dokan/dokan.c#L798

The attached zip file is a clear reproduction of the issue, if you will have a chance to run it, it would be more clear I think.

I just tried to repro on my side by adding the Thread.Sleep(50) before each Read and Write. Beside word being slower to save, it was able to save without any problem.

This must be a timing issue which sometimes it can be hard to repro on another env. The best would be for you to try to repro with procmon and analyze the Dokan logs to see what the difference between success and failure. Feel free to share here any piece you could find so we can help.

MagaKhachatryan commented 2 years ago

Hi @Liryna .You are absolutely true. I tried to reproduce the issue on other PCs and it didn't happen. We realized that most likely it is a cache problem, because when I renamed the original file on my PC and then moved it to Dokan Drive it started to work correctly and it worked correctly also for files that hadn't been in Drive before. So, thank you for your response and your patience very much!!!

Liryna commented 2 years ago

Glad this got it solved and thanks for updating the issue!