Skip to content

Commit

Permalink
Merge pull request #14 from liuwenping/master
Browse files Browse the repository at this point in the history
minor: fix ReuseHarvester dead block
  • Loading branch information
liuwenping authored Nov 3, 2021
2 parents ca03d8b + 2007a0f commit 95c90ec
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion filebeat/input/log/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ func (r *ReuseHarvester) Next() (reader.Message, error) {
select {
case <-r.done:
return reader.Message{}, ErrHarvesterDone
case <-r.fileReader.done:
return reader.Message{}, ErrHarvesterDone
case msg := <-r.message:
return msg.message, msg.error
}
Expand All @@ -118,6 +120,8 @@ func (r *ReuseHarvester) OnMessage(message ReuseMessage) error {
select {
case <-r.done:
return ErrHarvesterDone
case <-r.fileReader.done:
return ErrHarvesterDone
case r.message <- message:
return nil
}
Expand Down Expand Up @@ -289,7 +293,15 @@ func (h *FileHarvester) AddForwarder(reuseReader *ReuseHarvester) error {
}

//add forwarder
go func() { h.forwarder <- reuseReader }()
go func() {
select {
case <-h.done:
logp.Err("add forwarder failed, because FileHarvester is quit")
return
case h.forwarder <- reuseReader:
return
}
}()

// start to read file
h.runOnce.Do(func() {
Expand Down

0 comments on commit 95c90ec

Please sign in to comment.