Skip to content

Commit

Permalink
FS watcher failures cancel all log watches
Browse files Browse the repository at this point in the history
  • Loading branch information
mcphailtom committed Oct 17, 2023
1 parent 683d233 commit 44bcb49
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/version/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.4.0
v0.4.1
4 changes: 2 additions & 2 deletions logfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func newLogFile(fp string, bs int) (*logFile, error) {
// If the file does not exist at startup, the data processor will wait for the file to be created before continuing.
//
// The data processor expects the log data to be newline delimited
func (lf *logFile) dataProcessor(ctx context.Context, ewCancelChan <-chan error, stopChan chan<- string) {
func (lf *logFile) dataProcessor(ctx context.Context, ewCancelChan <-chan struct{}, stopChan chan<- string) {
go func() {
defer close(lf.dataChan)
defer close(lf.errorChan)
Expand Down Expand Up @@ -181,7 +181,7 @@ func (lf *logFile) dataProcessor(ctx context.Context, ewCancelChan <-chan error,
continue readLoop
}
continue
case err := <-ewCancelChan:
case <-ewCancelChan:
stopChan <- lf.filePath
lf.errorChan <- NewLogWhaleError(ErrorStateCancelled, fmt.Sprintf("operation cancelled"), err)
return
Expand Down
10 changes: 5 additions & 5 deletions logmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type LogManager struct {
ctx context.Context
ctxCancel context.CancelFunc

evwCancelChan chan error // event watcher cancel channel
evwCancelChan chan struct{} // event watcher cancel channel
fileWatcher *fsnotify.Watcher

lwMutex *sync.RWMutex // lwMutex is a mutex for the logsWatched map
Expand Down Expand Up @@ -65,7 +65,7 @@ func NewLogManager(ctx context.Context, options ...Option) (*LogManager, error)
pathsWatched: make(map[string]int),
pwMutex: &sync.RWMutex{},

evwCancelChan: make(chan error),
evwCancelChan: make(chan struct{}),
removeChan: make(chan string),
}

Expand Down Expand Up @@ -224,7 +224,7 @@ func (lm *LogManager) eventWatcher() {
return
case fse, ok := <-lm.fileWatcher.Events:
if !ok {
lm.evwCancelChan <- fmt.Errorf("file watcher closed unexpectedly")
close(lm.evwCancelChan)
return
}

Expand Down Expand Up @@ -268,8 +268,8 @@ func (lm *LogManager) eventWatcher() {
lm.lwMutex.RUnlock()
continue
}
case err := <-lm.fileWatcher.Errors:
lm.evwCancelChan <- err
case <-lm.fileWatcher.Errors:
close(lm.evwCancelChan)
return
}
}
Expand Down

0 comments on commit 44bcb49

Please sign in to comment.