From dca223d33bb25b25e0474dd240eda08d318bf5eb Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Wed, 2 Jun 2021 18:23:30 +0200 Subject: [PATCH] [bytestream] be careful not to hang goroutines writing to putResult If this goroutine blocks trying to write to putResult after Write exits then it will leak. We can avoid this by making putResult a buffered channel with length 1, since a Write call will send to this channel at most once. Then that single send will never block, and the goroutine can exit. While we're at it, let's make recvResult buffered too, just in case. Fixes #444. --- server/grpc_bytestream.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/grpc_bytestream.go b/server/grpc_bytestream.go index e320d6d57..4f43d6e9a 100644 --- a/server/grpc_bytestream.go +++ b/server/grpc_bytestream.go @@ -234,8 +234,8 @@ func (s *grpcServer) Write(srv bytestream.ByteStream_WriteServer) error { var resp bytestream.WriteResponse pr, pw := io.Pipe() - putResult := make(chan error) - recvResult := make(chan error) + putResult := make(chan error, 1) + recvResult := make(chan error, 1) resourceNameChan := make(chan string, 1) go func() { @@ -297,7 +297,8 @@ func (s *grpcServer) Write(srv bytestream.ByteStream_WriteServer) error { } go func() { - putResult <- s.cache.Put(cache.CAS, hash, size, pr) + err := s.cache.Put(cache.CAS, hash, size, pr) + putResult <- err }() firstIteration = false