From 67e0fea647e79df70ac9071683323ece730858f8 Mon Sep 17 00:00:00 2001 From: Mostyn Bramley-Moore Date: Fri, 23 Aug 2024 22:30:02 +0200 Subject: [PATCH] Ensure that DecoderWrappers are returned to the pool after use in bytestream Writes This is an alternative fix to #770. Thanks to Thorbjorn Larsson @tobbe76 for reporting this issue. --- server/grpc_bytestream.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/server/grpc_bytestream.go b/server/grpc_bytestream.go index 88099b71e..b24969ca7 100644 --- a/server/grpc_bytestream.go +++ b/server/grpc_bytestream.go @@ -15,8 +15,6 @@ import ( "github.com/buchgr/bazel-remote/v2/cache" "github.com/buchgr/bazel-remote/v2/cache/disk/casblob" - "github.com/klauspost/compress/zstd" - "github.com/buchgr/bazel-remote/v2/utils/zstdpool" syncpool "github.com/mostynb/zstdpool-syncpool" ) @@ -367,7 +365,7 @@ func (s *grpcServer) Write(srv bytestream.ByteStream_WriteServer) error { resourceNameChan := make(chan string, 1) cmp := casblob.Identity - var dec *zstd.Decoder + var dec *syncpool.DecoderWrapper defer func() { if dec != nil { dec.Close() @@ -438,7 +436,8 @@ func (s *grpcServer) Write(srv bytestream.ByteStream_WriteServer) error { var rc io.ReadCloser = pr if cmp == casblob.Zstandard { - dec, ok := decoderPool.Get().(*syncpool.DecoderWrapper) + var ok bool + dec, ok = decoderPool.Get().(*syncpool.DecoderWrapper) if !ok { s.accessLogger.Printf("GRPC BYTESTREAM WRITE FAILED: %s", errDecoderPoolFail) recvResult <- errDecoderPoolFail