@@ -10,7 +10,9 @@ import (
10
10
"os"
11
11
"os/exec"
12
12
"strings"
13
+ "time"
13
14
15
+ "github.com/cenkalti/backoff"
14
16
"github.com/opentracing/opentracing-go"
15
17
"golang.org/x/xerrors"
16
18
@@ -66,14 +68,36 @@ func (ws *GitInitializer) Run(ctx context.Context, mappings []archive.IDMapping)
66
68
return
67
69
}
68
70
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 )
71
93
}
72
94
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 {
75
98
return src , xerrors .Errorf ("git initializer: %w" , err )
76
99
}
100
+
77
101
if ws .Chown {
78
102
// TODO (aledbf): refactor to remove the need of manual chown
79
103
args := []string {"-R" , "-L" , "gitpod" , ws .Location }
0 commit comments