dokan-dev / dokany

User mode file system library for windows with FUSE Wrapper
http://dokan-dev.github.io
5.2k stars 661 forks source link

ReadFile returns error in case it takes long time to process. #846

Closed shino0729 closed 4 years ago

shino0729 commented 4 years ago

Feature request can skip this form. Bug report must complete it. Check List must be 100% match or it will be automatically closed without further discussion. Please remove this line.

Environment

Check List

Description

When ReadFile() callback takes long time, an application get the error even if the timeout of Dokan is set long time (or use DokanResetTimeout() function). The error is occurred in 5~10 minutes after the application starts to read. When I made Windows Defender off, the application succeed to read the file. I checked file I/O using Process Monitor, the process of Windows Defender try to read before the application read the file. Do you have any idea for this behavior?

Following is a test code to reproduce. I made some changes to mirror sample (mirror.c). I assume that the file is offline and it takes long time to read.

BOOL g_test_flag = TRUE;

static NTSTATUS DOKAN_CALLBACK MirrorReadFile(LPCWSTR FileName,
                                              LPVOID Buffer,
                                              DWORD BufferLength,
                                              LPDWORD ReadLength,
                                              LONGLONG Offset,
                                              PDOKAN_FILE_INFO DokanFileInfo) {
  ---

  // added code
  {
    // assumed that a file can be read in 10 minutes.
    if (wcsstr(FileName, L"test.dat")) {
      int count = 0;
      while (g_test_flag && count < 10) {
        Sleep(60 * 1000);  // 1 min.
        ++count;
        DokanResetTimeout(DokanFileInfo->DokanOptions->Timeout, DokanFileInfo);
      }
      g_test_flag = FALSE;
    }
  }

  return STATUS_SUCCESS;
}

And I run mirror sample as shown below.

> mirror.exe /r d:\mirror /l z /o /i 120000

I got an error when I tried to read a file ("test.dat") by using command prompt as like this. The error seems to be one of the timeout error.

> Z:  (move to z drive)
> type test.dat
Insufficient system resources exist to complete the requested service.
Liryna commented 4 years ago

Hi @shino0729

Thank you for the report. The error is occurred in 5~10 minutes after the application starts to read. do you mean during this time none of the read will pass ?

It would not surprise me that Windows Defender will respond to the request instead of us. He might have himself a timeout on the request he spies. To be sure this should be tracked in a debugger but I am not very sure we can do anything about it. 5-10min is very long for each read quest. How did you achieve to get such time in a real case ?

For information, you can return less data that requested and normally you should get a later request to retrieve the rest of the data.

shino0729 commented 4 years ago

Hi @Liryna ,

Thank you for your reply.

do you mean during this time none of the read will pass ?

Yes, it keeps blocking. I agree with your comment that Windows Defender has some timeout. If it's true, it is difficult to resolve with just the file system.

you can return less data that requested and normally you should get a later request to retrieve the rest of the data.

This is a good idea, but it cannot return any data until offline file becomes online and this takes long time in some cases (e.g. need to insert the media manually). If there is no solutions at the file system level, this issue will be closed.

Liryna commented 4 years ago

There is no possibilities unfortunately. The best would be to directly return an error or to only start the filesystem when the media is manually inserted.