Skip to content

Commit

Permalink
fixed inotify descriptor was closed in other goroutine while reading …
Browse files Browse the repository at this point in the history
…from it that caused a deadlock
  • Loading branch information
illarion committed Sep 16, 2024
1 parent 2d790be commit 56eb3c2
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 147 deletions.
10 changes: 8 additions & 2 deletions dirwatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ func NewDirWatcher(ctx context.Context, fileMask uint32, root string) (*DirWatch
return
}

select {
case <-ctx.Done():
close(events)
return
default:
}

for _, event := range raw {

// Skip ignored events queued from removed watchers
Expand Down Expand Up @@ -170,7 +177,6 @@ func NewDirWatcher(ctx context.Context, fileMask uint32, root string) (*DirWatch
return
}
}
return
case event, ok := <-events:
if !ok {
select {
Expand All @@ -197,8 +203,8 @@ func NewDirWatcher(ctx context.Context, fileMask uint32, root string) (*DirWatch
}()

go func() {
<-i.Done()
wg.Wait()
<-i.Done()
close(dw.done)
}()

Expand Down
Loading

0 comments on commit 56eb3c2

Please sign in to comment.