Skip to content

Commit

Permalink
fix livelog writer close
Browse files Browse the repository at this point in the history
  • Loading branch information
zc2638 committed Jan 17, 2024
1 parent 37871b4 commit 5660c1d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/livelog/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,18 @@ func (w *writer) Write(p []byte) (n int, err error) {
}

func (w *writer) Close() error {
close(w.closeCh)
w.closeCh <- struct{}{}

for {
select {
case line := <-w.lineCh:
w.lines = append(w.lines, line)
continue
default:
}
break
}

lineLen := len(w.lines)
if w.handler != nil && lineLen > 0 {
if lineLen > w.index {
Expand All @@ -78,6 +89,7 @@ func (w *writer) process() {
for {
select {
case <-w.closeCh:
close(w.closeCh)
return
case line := <-w.lineCh:
w.lines = append(w.lines, line)
Expand Down

0 comments on commit 5660c1d

Please sign in to comment.