Skip to content

Commit

Permalink
Merge pull request #6 from wnke/master
Browse files Browse the repository at this point in the history
Fix deadlock when reading and writer is closed.
  • Loading branch information
acomagu authored Jun 5, 2021
2 parents 2cfa345 + d05316d commit cd7a5f7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions bufpipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,6 @@ func (w *PipeWriter) CloseWithError(err error) error {
err = io.EOF
}
w.rerr = err
w.cond.Broadcast()
return nil
}
17 changes: 17 additions & 0 deletions bufpipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,20 @@ func TestPipeReader_CloseWithError(t *testing.T) {
is.Equal(err, expect)
is.Equal(n, 0)
}

func TestPipeReader_WriterCloseNoDeadlock(t *testing.T) {
r, w := bufpipe.New(nil)

done := make(chan struct{})
go func(t *testing.T) {
buf := make([]byte, 800)
r.Read(buf)
done <- struct{}{}
}(t)

time.Sleep(300 * time.Millisecond)
w.Close()

<-done
}

0 comments on commit cd7a5f7

Please sign in to comment.