Open qknight opened 1 year ago
Found a solution.
Triggered the bug with this
cp foo.mdwn foo1.mdwn
rm foo1.mdwn
cp foo.mdwn foo1.mdwn
rm foo1.mdwn
cp foo.mdwn foo1.mdwn
rm foo1.mdwn
cp foo.mdwn foo1.mdwn
rm foo1.mdwn
cp foo.mdwn foo1.mdwn
rm foo1.mdwn
cp foo.mdwn foo1.mdwn
rm foo1.mdwn
I found another occation created a slightly different error message which helped to identify the real issue:
panic: interface conversion: error is syscall.Errno, not *fs.PathError
goroutine 1337 [running]:
github.com/radovskyb/watcher.(*Watcher).retrieveFileList(0xc00011e080)
C:/Users/qknight/go/pkg/mod/github.com/radovskyb/watcher@v1.0.7/watcher.go:517 +0x4be
github.com/radovskyb/watcher.(*Watcher).Start(0xc00011e080, 0x5f5e100)
C:/Users/qknight/go/pkg/mod/github.com/radovskyb/watcher@v1.0.7/watcher.go:568 +0x158
main.fsNotifyWatchDocumentsDirectory({0xc000026640, 0x42})
C:/Users/qknight/Desktop/Projects/pankat/cmd/pankat-server/fsNotify.go:96 +0xc5
created by main.main
C:/Users/qknight/Desktop/Projects/pankat/cmd/pankat-server/main.go:35 +0x315
And this is the fix:
for name, recursive := range w.names {
if recursive {
list, err = w.listRecursive(name)
if err != nil {
+ e, ok := err.(syscall.Errno)
+ if ok && e.Is(err) {
if os.IsNotExist(err) {
w.mu.Unlock()
if name == err.(*os.PathError).Path {
w.Error <- ErrWatchedFileDeleted
w.RemoveRecursive(name)
}
w.mu.Lock()
} else {
w.Error <- err
}
+ }
}
} else {
list, err = w.list(name)
if err != nil {
+ e, ok := err.(syscall.Errno)
+ if ok && e.Is(err) {
if os.IsNotExist(err) {
w.mu.Unlock()
if name == err.(*os.PathError).Path {
w.Error <- ErrWatchedFileDeleted
w.Remove(name)
}
w.mu.Lock()
} else {
w.Error <- err
}
+ }
}
}
I'm not sure what this code does exactly and if my fix is correct but at least for me the watcher is now working according to specification!
Describe the bug A clear and concise description of what the bug is.
I changed a file which was observed by fsNotify and then the error occured:
https://github.com/nixcloud/pankat/blob/future/cmd/pankat-server/fsNotify.go#L63
To Reproduce
Expected behavior No crash, fsNotify just pointing out what files changed. This works very often, but sometimes crashes.
Which operating system and version are you using?
https://github.com/radovskyb/watcher#example