Skip to content

inotify: fix race in Close()#465

Merged
arp242 merged 1 commit intomainfrom
close-race
Jul 22, 2022
Merged

inotify: fix race in Close()#465
arp242 merged 1 commit intomainfrom
close-race

Conversation

@arp242
Copy link
Copy Markdown
Member

@arp242 arp242 commented Jul 22, 2022

Would sometimes fail with:

panic: close of closed channel

goroutine 204 [running]:
github.com/fsnotify/fsnotify.(*Watcher).Close(0xc0003e6410)
    	/home/martin/code/Golib/fsnotify/inotify.go:82 +0x66
created by github.com/fsnotify/fsnotify.TestCloseRace
    	/home/martin/code/Golib/fsnotify/integration_test.go:1256 +0x1a5
exit status 2

Because isClosed() might return "false" for two goroutines, and then
they will both try to close it, resulting in the panic.

Fixes #367

Would sometimes fail with:

	panic: close of closed channel

	goroutine 204 [running]:
	github.com/fsnotify/fsnotify.(*Watcher).Close(0xc0003e6410)
        	/home/martin/code/Golib/fsnotify/inotify.go:82 +0x66
	created by github.com/fsnotify/fsnotify.TestCloseRace
        	/home/martin/code/Golib/fsnotify/integration_test.go:1256 +0x1a5
	exit status 2

Because isClosed() might return "false" for two goroutines, and then
they will both try to close it, resulting in the panic.

Fixes #367
Copy link
Copy Markdown
Member

@shogo82148 shogo82148 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@arp242 arp242 merged commit 7fe2936 into main Jul 22, 2022
@arp242 arp242 deleted the close-race branch July 22, 2022 05:22
@shogo82148 shogo82148 mentioned this pull request Mar 6, 2024
25 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants