sending done would close w.kq before Remove had a chance to remove the watches with EV_DELETE, resulting in a file handle leak.
ref #59
also make Close() report the first error returned by Remove and continue.
closes #65
## master / 2015-02-07
* inotify: closing watcher should now always shut down goroutine [#63](https://github.com/go-fsnotify/fsnotify/pull/63) (thanks @PieterD)
+* kqueue: close kqueue after removing watches, fixes [#59](https://github.com/go-fsnotify/fsnotify/issues/59)
## v1.1.1 / 2015-02-05
<-removed2
}
+func TestClose(t *testing.T) {
+ // Regression test for #59 bad file descriptor from Close
+ testDir := tempMkdir(t)
+ defer os.RemoveAll(testDir)
+
+ watcher := newWatcher(t)
+ if err := watcher.Add(testDir); err != nil {
+ t.Fatalf("Expected no error on Add, got %v", err)
+ }
+ err := watcher.Close()
+ if err != nil {
+ t.Fatalf("Expected no error on Close, got %v.", err)
+ }
+}
+
func testRename(file1, file2 string) error {
switch runtime.GOOS {
case "windows", "plan9":
w.isClosed = true
w.mu.Unlock()
- // Send "quit" message to the reader goroutine:
- w.done <- true
-
w.mu.Lock()
ws := w.watches
w.mu.Unlock()
+
+ var err error
for name := range ws {
- w.Remove(name)
+ if e := w.Remove(name); e != nil && err == nil {
+ err = e
+ }
}
+ // Send "quit" message to the reader goroutine:
+ w.done <- true
+
return nil
}