@@ -21,10 +21,15 @@ import (
21
21
)
22
22
23
23
const (
24
- // urlCheckTimeout is the timeout used to check the source URL
25
- // If fetching the URL exceeds the timeout, then the build will
26
- // not proceed further and stop
27
- urlCheckTimeout = 16 * time .Second
24
+ // initialURLCheckTimeout is the initial timeout used to check the
25
+ // source URL. If fetching the URL exceeds the timeout, then a longer
26
+ // timeout will be tried until the fetch either succeeds or the build
27
+ // itself times out.
28
+ initialURLCheckTimeout = 16 * time .Second
29
+
30
+ // timeoutIncrementFactor is the factor to use when increasing
31
+ // the timeout after each unsuccessful try
32
+ timeoutIncrementFactor = 4
28
33
)
29
34
30
35
type gitAuthError string
@@ -104,35 +109,43 @@ func fetchSource(dockerClient DockerClient, dir string, build *api.Build, urlTim
104
109
// remote repository failed to authenticate.
105
110
// Since this is calling the 'git' binary, the proxy settings should be
106
111
// available for this command.
107
- func checkRemoteGit (gitClient GitClient , url string , timeout time.Duration ) error {
108
- glog .V (4 ).Infof ("git ls-remote --heads %s" , url )
112
+ func checkRemoteGit (gitClient GitClient , url string , initialTimeout time.Duration ) error {
109
113
110
114
var (
111
115
out string
112
116
errOut string
113
117
err error
114
118
)
115
119
116
- out , errOut , err = gitClient .TimedListRemote (timeout , url , "--heads" )
117
- if _ , ok := err .(* git.TimeoutError ); err != nil && ok {
118
- return fmt .Errorf ("timeout while waiting for remote repository %q" , url )
119
- }
120
-
121
- if len (out ) != 0 {
122
- glog .V (4 ).Infof (out )
123
- }
124
- if len (errOut ) != 0 {
125
- glog .V (4 ).Infof (errOut )
120
+ timeout := initialTimeout
121
+ for {
122
+ glog .V (4 ).Infof ("git ls-remote --heads %s" , url )
123
+ out , errOut , err = gitClient .TimedListRemote (timeout , url , "--heads" )
124
+ if len (out ) != 0 {
125
+ glog .V (4 ).Infof (out )
126
+ }
127
+ if len (errOut ) != 0 {
128
+ glog .V (4 ).Infof (errOut )
129
+ }
130
+ if err != nil {
131
+ if _ , ok := err .(* git.TimeoutError ); ok {
132
+ nextTimeout := timeout * timeoutIncrementFactor
133
+ glog .Infof ("WARNING: timed out waiting %s for git server, will wait %s" , timeout , nextTimeout )
134
+ timeout = nextTimeout
135
+ continue
136
+ }
137
+ }
138
+ break
126
139
}
127
-
128
- combinedOut := out + errOut
129
- switch {
130
- case strings .Contains (combinedOut , "Authentication failed" ):
131
- return gitAuthError (url )
132
- case strings .Contains (combinedOut , "not found" ):
133
- return gitNotFoundError (url )
140
+ if err != nil {
141
+ combinedOut := out + errOut
142
+ switch {
143
+ case strings .Contains (combinedOut , "Authentication failed" ):
144
+ return gitAuthError (url )
145
+ case strings .Contains (combinedOut , "not found" ):
146
+ return gitNotFoundError (url )
147
+ }
134
148
}
135
-
136
149
return err
137
150
}
138
151
0 commit comments