illarion / gonotify

Inotify wrapper
MIT License
30 stars 5 forks source link

Panics when sending to closed channel #6

Closed akemrir closed 2 months ago

akemrir commented 2 months ago

Hi,

I am programming one app using this library. Currently I've moved to newest go release, and I've done upgrade of deps.

I've encountered an issue with channels on very heavy load.

panic: send on closed channel

goroutine 34 [running]:
github.com/illarion/gonotify/v2.NewInotify.func1()
        github.com/illarion/gonotify/v2@v2.0.2/inotify.go:105 +0x52d
created by github.com/illarion/gonotify/v2.NewInotify in goroutine 1
        github.com/illarion/gonotify/v2@v2.0.2/inotify.go:70 +0x19a

It's easy to reproduce with two loops executed in separate shells:

while true
          touch views/x{29,30,40,50,60}.go
          rm views/x{29,30,40,50,60}.go
end
while true
          touch views/x{129,130,140,150,160}.go
          rm views/x{129,130,140,150,160}.go
end

I noticed that you are closing channel either way, hence small update. After the fix it stopped to panic. Please review the changes.

akemrir commented 2 months ago

@illarion What do you recon?

illarion commented 2 months ago

Yes, you're right, this code is could cause a panic, thank you!