Skip to content

There is a race in inotify.go:watcher.Close() #367

@zeripath

Description

@zeripath

Hi!

Thanks a lot for this library.

Looking at the code I'm suspicious that there is a race in Close():

fsnotify/inotify.go

Lines 72 to 80 in 7f4cf4d

// Close removes all watches and closes the events channel.
func (w *Watcher) Close() error {
if w.isClosed() {
return nil
}
// Send 'close' signal to goroutine, and set the Watcher to closed.
close(w.done)

Is it possible that two concurrent goroutines running Close() could both pass the check function w.isClosed() and then both call close(w.done)? That would result in two closes of the channel and a panic.

One solution would be to lock the w.mu at least around the w.IsClosed and close(w.done) calls.

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