Set connection timeout to 120 sec for SSH remote operations

The creation of a missing Git, before starting replication, is a
blocking operation. By setting a timeout on the synchronized
getSession(), we ensure the operation does not get stuck forever,
essentially blocking all future remote git creation operations.

120 seconds is an arbitrary limit, chosen because it should be enough
to not risk being triggered unnecessarily. This is a fail-safe and we
should hopefully very rarely end up needing the timeout.

Change-Id: I01ed29004c6c75a75ede918f61fa1c68d246150b
diff --git a/src/main/java/com/googlesource/gerrit/plugins/replication/ b/src/main/java/com/googlesource/gerrit/plugins/replication/
index 8be6b21..a34ac1c 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/replication/
+++ b/src/main/java/com/googlesource/gerrit/plugins/replication/
@@ -62,6 +62,7 @@
     HeadUpdatedListener {
   static final String REPLICATION_LOG_NAME = "replication_log";
   static final Logger repLog = LoggerFactory.getLogger(REPLICATION_LOG_NAME);
+  private static final int SSH_REMOTE_TIMEOUT = 120 * 1000;
   private static final ReplicationStateLogger stateLog =
       new ReplicationStateLogger(repLog);
@@ -413,7 +414,8 @@
   private static RemoteSession connect(URIish uri) throws TransportException {
-    return SshSessionFactory.getInstance().getSession(uri, null, FS.DETECTED, 0);
+    return SshSessionFactory.getInstance().getSession(uri, null, FS.DETECTED,
   private static OutputStream newErrorBufferStream() {