SpartanJ / efsw

efsw is a C++ cross-platform file system watcher and notifier.
Other
662 stars 101 forks source link

Crash in FileWatcher destructor on WIN32 #90

Closed SpartanJ closed 8 years ago

SpartanJ commented 8 years ago

Original report by Guillaume BOTTESI (Bitbucket: gbottesi, GitHub: gbottesi).


Hi!

Sometimes, depending on hardware, I have a crash when deleting an instance of FileWatcher. It seems to happen if I have overlapped operations during DestroyWatch method.

I fixed it by replacing CancelIO by CancelIOEx in DestroyWatch (and, bonus, I could then remove the 5ms sleep.)

Here is how it looks like :

    tWatch->StopNow = true;
    CancelIoEx(tWatch->DirHandle, &pWatch->Overlapped);
    RefreshWatch(pWatch);
    CloseHandle(pWatch->Overlapped.hEvent);
    CloseHandle(pWatch->Watch->DirHandle);
    efSAFE_DELETE_ARRAY(pWatch->Watch->DirName);
    efSAFE_DELETE( pWatch->Watch );
    HeapFree(GetProcessHeap(), 0, pWatch);

This is quite a random bug and I don't really have a way to reproduce (well other than my complete soft here which I can't really give you).

Reading MSDN : https://msdn.microsoft.com/en-us/library/windows/desktop/aa365683%28v=vs.85%29.aspx

It's said :

CancelIo—this function only cancels operations issued by the calling thread for the specified file handle.
CancelIoEx—this function cancels all operations issued by the threads for the specified file handle.

I think we may have operation from different threads in your lib...

SpartanJ commented 8 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


Thanks for reporting both bugs, since i cannot reproduce this one i'll just trust in your fix ( that makes total sense ).

SpartanJ commented 8 years ago

Original comment by Martín Lucas Golini (Bitbucket: SpartanJ, GitHub: SpartanJ).


Fixed issue #50. Fixed issue #51. Thanks to Guillaume Bottesi.