Skip to content

πŸ™Œ OpenHands: AI-Driven Development

fix ExceptionPxssh (#2023)

Xingyao Wangcbf4c4b4c41a
diff --git a/opendevin/runtime/docker/ssh_box.py b/opendevin/runtime/docker/ssh_box.py
index 75ac3fd860..72ef51321c 100644
--- a/opendevin/runtime/docker/ssh_box.py
+++ b/opendevin/runtime/docker/ssh_box.py
@@ -361,11 +361,25 @@ class DockerSSHBox(Sandbox):
environment=self._env,
)
- def start_ssh_session(self):
- # start ssh session at the background
- self.ssh = pxssh.pxssh(
- echo=False, timeout=self.timeout, encoding='utf-8', codec_errors='replace'
- )
+ def start_ssh_session(self, n_retries=5):
+ while n_retries > 0:
+ try:
+ self.ssh = pxssh.pxssh(
+ echo=False,
+ timeout=self.timeout,
+ encoding='utf-8',
+ codec_errors='replace',
+ )
+ break
+ except pxssh.ExceptionPxssh as e:
+ logger.exception(
+ 'Failed to start SSH session, retrying...', exc_info=False
+ )
+ n_retries -= 1
+ if n_retries == 0:
+ raise e
+ time.sleep(5)
+
hostname = self.ssh_hostname
if self.run_as_devin:
username = 'opendevin'