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 18:14:15 +0300
commit8cf09355f02543471a6836f3289bc92eeba6f594 (patch)
tree03fd8bd742f4e7e663573da9dd1472b865e890bf
parentd433d09056e4efcdfc6e748d1441e08ca35da91b (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")
+ }
}
}()