From 3aa51473456c8e1e042708c8e0c4235505010f13 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 | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/server/grpc_bytestream.go b/server/grpc_bytestream.go index 88099b71e..2231c42e6 100644 --- a/server/grpc_bytestream.go +++ b/server/grpc_bytestream.go @@ -15,7 +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 +366,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 +447,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 }()