Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SFTP Adapter (phpseclib v3)] Retry mechanism doesn't work #1450

Closed
lcobucci opened this issue Apr 19, 2022 · 2 comments · Fixed by #1451
Closed

[SFTP Adapter (phpseclib v3)] Retry mechanism doesn't work #1450

lcobucci opened this issue Apr 19, 2022 · 2 comments · Fixed by #1451

Comments

@lcobucci
Copy link
Contributor

Bug Report

Q A
BC Break no
Version 2.4.4

Summary

In phpseclibv3 we have exceptions when dealing with unreliable connections, which isn't handled well by SftpConnectionProvider and cause the retry mechanism to be bypassed.

public function provideConnection(): SFTP
{
$tries = 0;
start:
$connection = $this->connection instanceof SFTP
? $this->connection
: $this->setupConnection();
if ( ! $this->connectivityChecker->isConnected($connection)) {
$connection->disconnect();
$this->connection = null;
if ($tries < $this->maxTries) {
$tries++;
goto start;
}
throw UnableToConnectToSftpHost::atHostname($this->host);
}
return $this->connection = $connection;
}
private function setupConnection(): SFTP
{
$connection = new SFTP($this->host, $this->port, $this->timeout);
$connection->setPreferredAlgorithms($this->preferredAlgorithms);
$connection->disableStatCache();
try {
$this->checkFingerprint($connection);
$this->authenticate($connection);
} catch (Throwable $exception) {
$connection->disconnect();
throw $exception;
}
return $connection;
}

How to reproduce

Testing and reproducing this requires a flaky connection, here's a snippet that isolates the problem: https://3v4l.org/KmXsL

@lcobucci
Copy link
Contributor Author

@frankdejonge a possible solution would be catching the exceptions and relying on null. Would be nice to have your input before sending a PR :)

@lcobucci
Copy link
Contributor Author

Closing here as #1451 has been released 👍
Thanks @frankdejonge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant