Skip to content

Commit

Permalink
Add timeout for remote git operations
Browse files Browse the repository at this point in the history
  • Loading branch information
zentol committed Oct 8, 2021
1 parent 7981fd5 commit fa9841e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/ververica/git/GitActionsImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.UUID;

public class GitActionsImpl implements GitActions {
private static final Path LOCAL_REPO_PATH = Paths.get("repo_" + UUID.randomUUID(), ".git");
private static final Logger LOG = LoggerFactory.getLogger(GitActionsImpl.class);

private final Git git;
private final int operationTimeoutInSeconds = (int) Duration.ofMinutes(10).getSeconds();

public GitActionsImpl(final Path temporaryDirectory) throws IOException {
final Path repoPath = temporaryDirectory.resolve(LOCAL_REPO_PATH);
Expand Down Expand Up @@ -96,6 +98,7 @@ public void fetchBranch(String remoteBranchName, String remoteName, boolean fetc
// this should use a logger instead, but this would break the output being updated in-place
.setProgressMonitor(new TextProgressMonitor())
.setRefSpecs(refSpec)
.setTimeout(operationTimeoutInSeconds)
.call();
} catch (GitAPIException e) {
throw new GitException(e);
Expand Down Expand Up @@ -140,6 +143,7 @@ private void internalPushGitBranch(String localBranchName, String remoteBranchNa
.setRemote(remoteName)
.setCredentialsProvider(new UsernamePasswordCredentialsProvider(authenticationToken, ""))
.setForce(force)
.setTimeout(operationTimeoutInSeconds)
.call();
for (PushResult pushResult : pushResults) {
LOG.debug(pushResult.getRemoteUpdates().toString());
Expand Down

0 comments on commit fa9841e

Please sign in to comment.