]> Cypherpunks repositories - gostls13.git/commitdiff
exp/inotify: close event channel before file descriptor
authorIan Lance Taylor <iant@golang.org>
Tue, 5 Feb 2013 14:11:10 +0000 (06:11 -0800)
committerIan Lance Taylor <iant@golang.org>
Tue, 5 Feb 2013 14:11:10 +0000 (06:11 -0800)
Closing the inotify file descriptor can take over a second
when running on Ubuntu Precise in an NFS directory, leading to
the test error in issue 3132.  Closing the event channel first
lets a client that does not care about the error channel move
on.

Fixes #3132.

R=golang-dev, dave, rsc
CC=golang-dev
https://golang.org/cl/7300045

src/pkg/exp/inotify/inotify_linux.go

index f989a9224d980e8f4fdd7c2a92f64ab7359b16a0..f671f47a1308b0442b6098b85e74a2b49acaec2a 100644 (file)
@@ -153,7 +153,7 @@ func (w *Watcher) readEvents() {
        var buf [syscall.SizeofInotifyEvent * 4096]byte
 
        for {
-               n, err := syscall.Read(w.fd, buf[0:])
+               n, err := syscall.Read(w.fd, buf[:])
                // See if there is a message on the "done" channel
                var done bool
                select {
@@ -163,11 +163,13 @@ func (w *Watcher) readEvents() {
 
                // If EOF or a "done" message is received
                if n == 0 || done {
+                       // The syscall.Close can be slow.  Close
+                       // w.Event first.
+                       close(w.Event)
                        err := syscall.Close(w.fd)
                        if err != nil {
                                w.Error <- os.NewSyscallError("close", err)
                        }
-                       close(w.Event)
                        close(w.Error)
                        return
                }