Skip to content

Commit

Permalink
Ensure that DecoderWrappers are returned to the pool after use in byt…
Browse files Browse the repository at this point in the history
…estream Writes

This is an alternative fix to #770.

Thanks to Thorbjorn Larsson @tobbe76 for reporting this issue.
  • Loading branch information
mostynb committed Aug 24, 2024
1 parent e83828a commit 67e0fea
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions server/grpc_bytestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 67e0fea

Please sign in to comment.