Skip to content

macOS: Close() does not release kqueue fd synchronously #333

@dottedmag

Description

@dottedmag

Which operating system (GOOS) and version are you using?

macOS: 10.14.6

Please describe the issue that occurred.

The following test fails:

func TestOpenCloseQuickly(t *testing.T) {
	name := tempMkFile(t, "")

	for i := 0; i < 1000; i++ {
		w := newWatcher(t)
		err := w.Add(name)
		if err != nil {
			t.Fatal(err)
		}
		err = w.Close()
		if err != nil {
			t.Fatal(err)
		}
	}
}

with

=== RUN   TestOpenCloseQuickly
    TestOpenCloseQuickly: integration_test.go:51: failed to create test file: open /var/folders/bw/6hyp_vyj68v973qbhlbcvlcr0000gn/T/fsnotify232022216: too many open files
--- FAIL: TestOpenCloseQuickly (0.00s)

The problem is that w.Close() returns before reader goroutine closes the kqueue fd.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions