Просмотр исходного кода

Add retry logic to ssh login (#2053)

* add retry logic to ssh login

* Update opendevin/runtime/docker/ssh_box.py

Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>

---------

Co-authored-by: Engel Nyst <enyst@users.noreply.github.com>
Xingyao Wang 1 год назад
Родитель
Сommit
221035d39a
1 измененных файлов с 17 добавлено и 1 удалено
  1. 17 1
      opendevin/runtime/docker/ssh_box.py

+ 17 - 1
opendevin/runtime/docker/ssh_box.py

@@ -386,7 +386,23 @@ class DockerSSHBox(Sandbox):
             f"If you encounter any issues, you can try `ssh -v -p {self._ssh_port} {username}@{hostname}` with the password '{self._ssh_password}' and report the issue on GitHub. "
             f"If you started OpenDevin with `docker run`, you should try `ssh -v -p {self._ssh_port} {username}@localhost` with the password '{self._ssh_password} on the host machine (where you started the container)."
         )
-        self.ssh.login(hostname, username, self._ssh_password, port=self._ssh_port)
+
+        # TODO there's a similar block nearby, replace with some retry decorator instead or something
+        n_retries = 5
+        while n_retries > 0:
+            try:
+                self.ssh.login(
+                    hostname, username, self._ssh_password, port=self._ssh_port
+                )
+                break
+            except pxssh.ExceptionPxssh as e:
+                logger.exception(
+                    'Failed to login to SSH session, retrying...', exc_info=False
+                )
+                n_retries -= 1
+                if n_retries == 0:
+                    raise e
+                time.sleep(5)
 
         # Fix: https://github.com/pexpect/pexpect/issues/669
         self.ssh.sendline("bind 'set enable-bracketed-paste off'")