Skip to content

Commit

Permalink
Merge pull request #1441 from ploxiln/spreadwriter_flush_empty
Browse files Browse the repository at this point in the history
SpreadWriter: fix flush panic with zero writes
  • Loading branch information
mreiferson authored Mar 6, 2023
2 parents b28153e + af67175 commit 1362af1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/writers/spread_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func (s *SpreadWriter) Write(p []byte) (int, error) {
}

func (s *SpreadWriter) Flush() {
if len(s.buf) == 0 {
// nothing to write, just wait
select {
case <-time.After(s.interval):
case <-s.exitCh:
}
return
}
sleep := s.interval / time.Duration(len(s.buf))
ticker := time.NewTicker(sleep)
for _, b := range s.buf {
Expand Down

0 comments on commit 1362af1

Please sign in to comment.