Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Okstad <pokstad@gitlab.com>2020-08-26 02:18:07 +0300
committerPaul Okstad <pokstad@gitlab.com>2020-08-26 17:57:33 +0300
commit3f880eabfaf69ecae4560a8dd4a23b187b8b00b9 (patch)
treec7e48dc5a2a4f97ab35d1acecc48257bdde421f7
parentffdac2a773fe79c7f99d2d7c5a1b8a0f28b5e7d4 (diff)
Discard remaining stream when cache fails
This resolves the issue where the info ref RPC hangs when a failure occurs while persisting a response stream. The fix discards any remaining bytes in the tee reader used by the cache when the cache operation cannot proceed. This unblocks the tee reader so that the normal non-cache mechanism can proceed to serving the request.
-rw-r--r--changelogs/unreleased/po-fix-inforef-stuck.yml5
-rw-r--r--internal/service/smarthttp/cache.go9
2 files changed, 14 insertions, 0 deletions
diff --git a/changelogs/unreleased/po-fix-inforef-stuck.yml b/changelogs/unreleased/po-fix-inforef-stuck.yml
new file mode 100644
index 000000000..4aeb54d15
--- /dev/null
+++ b/changelogs/unreleased/po-fix-inforef-stuck.yml
@@ -0,0 +1,5 @@
+---
+title: Fix hanging info refs cache when error occurs
+merge_request: 2497
+author:
+type: fixed
diff --git a/internal/service/smarthttp/cache.go b/internal/service/smarthttp/cache.go
index 0742d6e81..bb953f78c 100644
--- a/internal/service/smarthttp/cache.go
+++ b/internal/service/smarthttp/cache.go
@@ -3,6 +3,7 @@ package smarthttp
import (
"context"
"io"
+ "io/ioutil"
"sync"
"github.com/golang/protobuf/proto"
@@ -92,6 +93,14 @@ func tryCache(ctx context.Context, in *gitalypb.InfoRefsRequest, w io.Writer, mi
tr := io.TeeReader(pr, w)
if err := infoRefCache.PutStream(ctx, in.Repository, in, tr); err != nil {
logger.Errorf("unable to store InfoRefsUploadPack response in cache: %q", err)
+
+ // discard remaining bytes if caching stream
+ // failed so that tee reader is not blocked
+ _, err = io.Copy(ioutil.Discard, tr)
+ if err != nil {
+ logger.WithError(err).
+ Error("unable to discard remaining InfoRefsUploadPack cache stream")
+ }
}
}()