Skip to content

Commit

Permalink
[JENKINS-11286] run git commands with a time-out
Browse files Browse the repository at this point in the history
  • Loading branch information
ndeloof committed Oct 28, 2013
1 parent ddfde14 commit 1b7fd2b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
Expand Up @@ -51,6 +51,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -973,7 +974,7 @@ private String launchCommandIn(ArgumentListBuilder args, File workDir, String pu
Launcher.ProcStarter p = launcher.launch().cmds(args.toCommandArray()).
envs(environment).stdout(fos).stderr(err);
if (workDir != null) p.pwd(workDir);
int status = p.join();
int status = p.start().joinWithTimeout(TIMEOUT, TimeUnit.MINUTES, listener);

String result = fos.toString();
if (status != 0) {
Expand Down Expand Up @@ -1483,4 +1484,12 @@ public List<String> call() throws RuntimeException {
return sshUser.getPrivateKeys();
}
}

/**
* preventive Time-out for git command execution.
* <p>
* We run git as an external process so can't guarantee it won't hang for whatever reason. Even plugin does its
* best to avoid git interactively asking for credentials, but there's a bunch of other cases git may hung.
*/
public static int TIMEOUT = Integer.getInteger(Git.class.getName() + ".timeOut", 10);
}

0 comments on commit 1b7fd2b

Please sign in to comment.