From 8c1cda86bf2f97ec7db1f393fd1b0bf3b57e7382 Mon Sep 17 00:00:00 2001 From: tobbe76 Date: Fri, 23 Aug 2024 14:16:14 +0200 Subject: [PATCH] Return zst Decoder to sync.pool when finished defered close for dec was broken due to shadowed variable so removed. Added defer close in the go func that calls cache.Put With this change we can handle higher load on the server without crash due GOMAXPROCS. --- server/grpc_bytestream.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/server/grpc_bytestream.go b/server/grpc_bytestream.go index 88099b71e..de554f128 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,12 +365,6 @@ func (s *grpcServer) Write(srv bytestream.ByteStream_WriteServer) error { resourceNameChan := make(chan string, 1) cmp := casblob.Identity - var dec *zstd.Decoder - defer func() { - if dec != nil { - dec.Close() - } - }() go func() { firstIteration := true @@ -454,6 +446,7 @@ func (s *grpcServer) Write(srv bytestream.ByteStream_WriteServer) error { } go func() { + defer rc.Close() err := s.cache.Put(srv.Context(), cache.CAS, hash, size, rc) putResult <- err }()