Skip to content

File handle leak on OS X #59

@neelance

Description

@neelance

The following code quickly runs into a panic: too many open files on OS X, even though the documentation says that Close removes all watches.

package main

import "gopkg.in/fsnotify.v1"

func main() {
    for {
        println("loop")

        w, err := fsnotify.NewWatcher()
        if err != nil {
            panic(err)
        }

        go func() {
            for range w.Events {
            }
        }()
        go func() {
            for range w.Errors {
            }
        }()

        if err := w.Add("test.go"); err != nil {
            panic(err)
        }

        // uncomment this to make the leak go away
        // if err := w.Remove("test.go"); err != nil {
        //  panic(err)
        // }

        if err := w.Close(); err != nil {
            panic(err)
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions