Skip to content

Commit 95421f0

Browse files
committed
builder: increase git check timeout exponentially
The check will either succeed or the build will timeout
1 parent 7afe72b commit 95421f0

File tree

3 files changed

+39
-26
lines changed

3 files changed

+39
-26
lines changed

pkg/build/builder/docker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func NewDockerBuilder(dockerClient DockerClient, buildsClient client.BuildInterf
4848
build: build,
4949
gitClient: gitClient,
5050
tar: tar.New(),
51-
urlTimeout: urlCheckTimeout,
51+
urlTimeout: initialURLCheckTimeout,
5252
client: buildsClient,
5353
cgLimits: cgLimits,
5454
}

pkg/build/builder/source.go

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ import (
2121
)
2222

2323
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
2833
)
2934

3035
type gitAuthError string
@@ -104,35 +109,43 @@ func fetchSource(dockerClient DockerClient, dir string, build *api.Build, urlTim
104109
// remote repository failed to authenticate.
105110
// Since this is calling the 'git' binary, the proxy settings should be
106111
// 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 {
109113

110114
var (
111115
out string
112116
errOut string
113117
err error
114118
)
115119

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
126139
}
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+
}
134148
}
135-
136149
return err
137150
}
138151

pkg/build/builder/sti.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (s *S2IBuilder) Build() error {
115115
download := &downloader{
116116
s: s,
117117
in: os.Stdin,
118-
timeout: urlCheckTimeout,
118+
timeout: initialURLCheckTimeout,
119119

120120
dir: srcDir,
121121
contextDir: contextDir,

0 commit comments

Comments
 (0)