Skip to content

Commit 5635a95

Browse files
[content-service] Retry git clone
1 parent f88bf1f commit 5635a95

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

components/content-service/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ go 1.16
55
require (
66
cloud.google.com/go/storage v1.14.0
77
github.com/Microsoft/hcsshim v0.8.15 // indirect
8+
github.com/cenkalti/backoff v2.2.1+incompatible
89
github.com/containerd/continuity v0.0.0-20210315143101-93e15499afd5 // indirect
910
github.com/gitpod-io/gitpod/common-go v0.0.0-00010101000000-000000000000
1011
github.com/gitpod-io/gitpod/content-service/api v0.0.0-00010101000000-000000000000

components/content-service/go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ github.com/bugsnag/bugsnag-go v0.0.0-20141110184014-b1d153021fcd/go.mod h1:2oa8n
118118
github.com/bugsnag/osext v0.0.0-20130617224835-0dd3f918b21b/go.mod h1:obH5gd0BsqsP2LwDJ9aOkm/6J86V6lyAXCoQWGw3K50=
119119
github.com/bugsnag/panicwrap v0.0.0-20151223152923-e2c28503fcd0/go.mod h1:D/8v3kj0zr8ZAKg1AQ6crr+5VwKN5eIywRkfhyM/+dE=
120120
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
121+
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
121122
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
122123
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
123124
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=

components/content-service/pkg/initializer/git.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
"os"
1111
"os/exec"
1212
"strings"
13+
"time"
1314

15+
"github.com/cenkalti/backoff"
1416
"github.com/opentracing/opentracing-go"
1517
"golang.org/x/xerrors"
1618

@@ -66,14 +68,36 @@ func (ws *GitInitializer) Run(ctx context.Context, mappings []archive.IDMapping)
6668
return
6769
}
6870

69-
if err := os.MkdirAll(ws.Location, 0770); err != nil {
70-
return src, xerrors.Errorf("git initializer: %w", err)
71+
gitClone := func() error {
72+
if err := os.MkdirAll(ws.Location, 0770); err != nil {
73+
return err
74+
}
75+
76+
log.WithField("stage", "init").WithField("location", ws.Location).Debug("Running git clone on workspace")
77+
return ws.Clone(ctx)
78+
}
79+
onGitCloneFailure := func(e error, d time.Duration) {
80+
if err := os.RemoveAll(ws.Location); err != nil {
81+
log.
82+
WithField("stage", "init").
83+
WithField("location", ws.Location).
84+
WithError(err).
85+
Error("Cleaning workspace location failed.")
86+
}
87+
log.
88+
WithField("stage", "init").
89+
WithField("location", ws.Location).
90+
WithField("sleepTime", d).
91+
WithError(e).
92+
Debugf("Running git clone on workspace failed. Retrying in %s ...", d)
7193
}
7294

73-
log.WithField("stage", "init").WithField("location", ws.Location).Debug("Running git clone on workspace")
74-
if err := ws.Clone(ctx); err != nil {
95+
b := backoff.NewExponentialBackOff()
96+
b.MaxElapsedTime = 5 * time.Minute
97+
if err = backoff.RetryNotify(gitClone, b, onGitCloneFailure); err != nil {
7598
return src, xerrors.Errorf("git initializer: %w", err)
7699
}
100+
77101
if ws.Chown {
78102
// TODO (aledbf): refactor to remove the need of manual chown
79103
args := []string{"-R", "-L", "gitpod", ws.Location}

0 commit comments

Comments
 (0)