Skip to content

Commit

Permalink
[bytestream] drain any remaining data after Put returns
Browse files Browse the repository at this point in the history
io.PipeWriter Write calls block until all the data written in the call
is read from the corresponding io.PipeReader. If we don't read all that
data, then the writing goroutine will block forever.

This PipeWriter is intended to be consumed by disk.Put(), but if that
returns early then there will be blocked writes. To un-block them, we
can ensure that any remaining data is drained after disk.Put returns.

This might fix buchgr#473
  • Loading branch information
mostynb committed Sep 20, 2021
1 parent ec6781d commit 911127a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/grpc_bytestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ func (s *grpcServer) Write(srv bytestream.ByteStream_WriteServer) error {

go func() {
err := s.cache.Put(cache.CAS, hash, size, rc)
_, _ = io.Copy(io.Discard, rc) // Ensure that the writing goroutine is unblocked.
putResult <- err
}()

Expand All @@ -460,7 +461,7 @@ func (s *grpcServer) Write(srv bytestream.ByteStream_WriteServer) error {
}
}

n, err := pw.Write(req.Data)
n, err := pw.Write(req.Data) // This blocks until all the data written here is read from pr.
if err != nil {
recvResult <- status.Error(codes.Internal, err.Error())
return
Expand Down

0 comments on commit 911127a

Please sign in to comment.