rjeczalik / notify

File system event notification library on steroids.
MIT License
902 stars 128 forks source link

readdcw: watching hangs forever if GetQueuedCompletionStatus returns zero transferred bytes #167

Closed FabianKramm closed 5 years ago

FabianKramm commented 5 years ago

Hello! I'm one of the maintainers of devspace, where we use notify as a file watcher in our synchronization functionality. Under some unclear circumstances the notify library seems to stop watching without any errors on windows in heavy load scenarios (several hundred file changes at once).

I investigated the problem and the issue seems to be in the function loop in the file watcher_readdcw.go. In the special case the windows api function GetQueuedCompletionStatus retrieves zero bytes in lpNumberOfBytes. This leads to the skip of calling the readdirchanges function, since n is zero:

if n != 0 {
    r.loopevent(n, overEx)
    if err = overEx.parent.readDirChanges(); err != nil {
        // TODO: error handling
    }
}

Which in the next loop iteration leads to the subsequent execution of GetQueuedCompletionStatus, which will hang forever. The solution is pretty simple, just call readDirChanges when n is zero. I created a pull request for this issue.

Thanks for the awesome library!