@@ -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,42 @@ 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
+ timeout = timeout * timeoutIncrementFactor
133
+ glog .Infof ("WARNING: timed out waiting for git server, will wait %s" , timeout )
134
+ continue
135
+ }
136
+ }
137
+ break
126
138
}
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 )
139
+ if err != nil {
140
+ combinedOut := out + errOut
141
+ switch {
142
+ case strings .Contains (combinedOut , "Authentication failed" ):
143
+ return gitAuthError (url )
144
+ case strings .Contains (combinedOut , "not found" ):
145
+ return gitNotFoundError (url )
146
+ }
134
147
}
135
-
136
148
return err
137
149
}
138
150
0 commit comments