Skip to content

Commit

Permalink
fix: catch SSHException to trigger the retry on connection dropped
Browse files Browse the repository at this point in the history
  • Loading branch information
Sanix-Darker committed Oct 13, 2023
1 parent eac79a3 commit e874a86
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion peakina/io/ftp/ftp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def ftp_open(url: str, retry: int = _DEFAULT_MAX_RETRY) -> IO[bytes]: # type: i
for i in range(1, retry + 1):
try:
return _open(url)
except (AttributeError, OSError, ftplib.error_temp) as e:
except (AttributeError, OSError, ftplib.error_temp, paramiko.SSHException) as e:
log = logging.getLogger(__name__)
# If this occurs, we need to see what's actually inside that dir
# by listing maxi 15 entries
Expand Down
2 changes: 2 additions & 0 deletions tests/io/ftp/test_ftp_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ssl
from urllib.parse import ParseResult

from paramiko.ssh_exception import SSHException
from pytest import fixture, raises
from pytest_mock import MockFixture

Expand Down Expand Up @@ -68,6 +69,7 @@ def test_retry_open(mocker):
ftplib.error_temp("421 Could not create socket"),
AttributeError("'NoneType' object has no attribute 'sendall'"),
OSError("Random OSError"),
SSHException("Random connection dropped error"),
"ok",
]
mock_sleep = mocker.patch("peakina.io.ftp.ftp_utils.sleep")
Expand Down

0 comments on commit e874a86

Please sign in to comment.