Merge pull request #198 from amnezia-vpn/bugfix/qssh-too-many-open-connections
bugfix/qssh-too-many-open-connections
This commit is contained in:
commit
15c33014e7
5 changed files with 10 additions and 23 deletions
|
@ -38,7 +38,7 @@ ErrorCode ServerController::runScript(const ServerCredentials &credentials, QStr
|
||||||
const std::function<void(const QString &, QSharedPointer<SshRemoteProcess>)> &cbReadStdOut,
|
const std::function<void(const QString &, QSharedPointer<SshRemoteProcess>)> &cbReadStdOut,
|
||||||
const std::function<void(const QString &, QSharedPointer<SshRemoteProcess>)> &cbReadStdErr)
|
const std::function<void(const QString &, QSharedPointer<SshRemoteProcess>)> &cbReadStdErr)
|
||||||
{
|
{
|
||||||
SshConnection *client = connectToHost(sshParams(credentials));
|
QSharedPointer<SshConnection> client = connectToHost(sshParams(credentials));
|
||||||
if (client->state() == SshConnection::State::Connecting) {
|
if (client->state() == SshConnection::State::Connecting) {
|
||||||
qDebug() << "ServerController::runScript aborted, connectToHost in progress";
|
qDebug() << "ServerController::runScript aborted, connectToHost in progress";
|
||||||
return ErrorCode::SshTimeoutError;
|
return ErrorCode::SshTimeoutError;
|
||||||
|
@ -229,7 +229,7 @@ QByteArray ServerController::getTextFileFromContainer(DockerContainer container,
|
||||||
|
|
||||||
qDebug().noquote() << "Copy file from container\n" << script;
|
qDebug().noquote() << "Copy file from container\n" << script;
|
||||||
|
|
||||||
SshConnection *client = connectToHost(sshParams(credentials));
|
QSharedPointer<SshConnection> client = connectToHost(sshParams(credentials));
|
||||||
if (client->state() != SshConnection::State::Connected) {
|
if (client->state() != SshConnection::State::Connected) {
|
||||||
if (errorCode) *errorCode = fromSshConnectionErrorCode(client->errorState());
|
if (errorCode) *errorCode = fromSshConnectionErrorCode(client->errorState());
|
||||||
return {};
|
return {};
|
||||||
|
@ -288,7 +288,7 @@ ErrorCode ServerController::checkOpenVpnServer(DockerContainer container, const
|
||||||
ErrorCode ServerController::uploadFileToHost(const ServerCredentials &credentials, const QByteArray &data, const QString &remotePath,
|
ErrorCode ServerController::uploadFileToHost(const ServerCredentials &credentials, const QByteArray &data, const QString &remotePath,
|
||||||
QSsh::SftpOverwriteMode overwriteMode)
|
QSsh::SftpOverwriteMode overwriteMode)
|
||||||
{
|
{
|
||||||
SshConnection *client = connectToHost(sshParams(credentials));
|
QSharedPointer<SshConnection> client = connectToHost(sshParams(credentials));
|
||||||
if (client->state() != SshConnection::State::Connected) {
|
if (client->state() != SshConnection::State::Connected) {
|
||||||
return fromSshConnectionErrorCode(client->errorState());
|
return fromSshConnectionErrorCode(client->errorState());
|
||||||
}
|
}
|
||||||
|
@ -780,23 +780,23 @@ QString ServerController::checkSshConnection(const ServerCredentials &credential
|
||||||
return stdOut;
|
return stdOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
SshConnection *ServerController::connectToHost(const SshConnectionParameters &sshParams)
|
QSharedPointer<SshConnection> ServerController::connectToHost(const SshConnectionParameters &sshParams)
|
||||||
{
|
{
|
||||||
SshConnection *client = acquireConnection(sshParams);
|
QSharedPointer<SshConnection> client(new SshConnection(sshParams));
|
||||||
if (!client) return nullptr;
|
if (!client.get()) return nullptr;
|
||||||
|
|
||||||
QEventLoop waitssh;
|
QEventLoop waitssh;
|
||||||
QObject::connect(client, &SshConnection::connected, &waitssh, [&]() {
|
QObject::connect(client.get(), &SshConnection::connected, &waitssh, [&]() {
|
||||||
qDebug() << "Server connected by ssh";
|
qDebug() << "Server connected by ssh";
|
||||||
waitssh.quit();
|
waitssh.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(client, &SshConnection::disconnected, &waitssh, [&]() {
|
QObject::connect(client.get(), &SshConnection::disconnected, &waitssh, [&]() {
|
||||||
qDebug() << "Server disconnected by ssh";
|
qDebug() << "Server disconnected by ssh";
|
||||||
waitssh.quit();
|
waitssh.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
QObject::connect(client, &SshConnection::error, &waitssh, [&](QSsh::SshError error) {
|
QObject::connect(client.get(), &SshConnection::error, &waitssh, [&](QSsh::SshError error) {
|
||||||
qCritical() << "Ssh error:" << error << client->errorString();
|
qCritical() << "Ssh error:" << error << client->errorString();
|
||||||
waitssh.quit();
|
waitssh.quit();
|
||||||
});
|
});
|
||||||
|
@ -839,12 +839,6 @@ void ServerController::setCancelInstallation(const bool cancel)
|
||||||
m_cancelInstallation = cancel;
|
m_cancelInstallation = cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerController::disconnectFromHost(const ServerCredentials &credentials)
|
|
||||||
{
|
|
||||||
SshConnection *client = acquireConnection(sshParams(credentials));
|
|
||||||
if (client) client->disconnectFromHost();
|
|
||||||
}
|
|
||||||
|
|
||||||
ErrorCode ServerController::setupServerFirewall(const ServerCredentials &credentials)
|
ErrorCode ServerController::setupServerFirewall(const ServerCredentials &credentials)
|
||||||
{
|
{
|
||||||
return runScript(credentials,
|
return runScript(credentials,
|
||||||
|
|
|
@ -31,7 +31,6 @@ public:
|
||||||
ErrorCode fromSshProcessExitStatus(int exitStatus);
|
ErrorCode fromSshProcessExitStatus(int exitStatus);
|
||||||
|
|
||||||
QSsh::SshConnectionParameters sshParams(const ServerCredentials &credentials);
|
QSsh::SshConnectionParameters sshParams(const ServerCredentials &credentials);
|
||||||
void disconnectFromHost(const ServerCredentials &credentials);
|
|
||||||
|
|
||||||
ErrorCode removeAllContainers(const ServerCredentials &credentials);
|
ErrorCode removeAllContainers(const ServerCredentials &credentials);
|
||||||
ErrorCode removeContainer(const ServerCredentials &credentials, DockerContainer container);
|
ErrorCode removeContainer(const ServerCredentials &credentials, DockerContainer container);
|
||||||
|
@ -72,7 +71,7 @@ public:
|
||||||
Vars genVarsForScript(const ServerCredentials &credentials, DockerContainer container = DockerContainer::None, const QJsonObject &config = QJsonObject());
|
Vars genVarsForScript(const ServerCredentials &credentials, DockerContainer container = DockerContainer::None, const QJsonObject &config = QJsonObject());
|
||||||
|
|
||||||
QString checkSshConnection(const ServerCredentials &credentials, ErrorCode *errorCode = nullptr);
|
QString checkSshConnection(const ServerCredentials &credentials, ErrorCode *errorCode = nullptr);
|
||||||
QSsh::SshConnection *connectToHost(const QSsh::SshConnectionParameters &sshParams);
|
QSharedPointer<QSsh::SshConnection> connectToHost(const QSsh::SshConnectionParameters &sshParams);
|
||||||
|
|
||||||
void setCancelInstallation(const bool cancel);
|
void setCancelInstallation(const bool cancel);
|
||||||
ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials, QMap<DockerContainer, QJsonObject> &installedContainers);
|
ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials, QMap<DockerContainer, QJsonObject> &installedContainers);
|
||||||
|
|
|
@ -45,7 +45,6 @@ void AdvancedServerSettingsLogic::onPushButtonClearServerClicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex));
|
ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex));
|
||||||
m_serverController->disconnectFromHost(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex));
|
|
||||||
if (e) {
|
if (e) {
|
||||||
emit uiLogic()->showWarningMessage(tr("Error occurred while cleaning the server.") + "\n" +
|
emit uiLogic()->showWarningMessage(tr("Error occurred while cleaning the server.") + "\n" +
|
||||||
tr("Error message: ") + errorString(e) + "\n" +
|
tr("Error message: ") + errorString(e) + "\n" +
|
||||||
|
|
|
@ -342,8 +342,6 @@ void UiLogic::installServer(QPair<DockerContainer, QJsonObject> &container)
|
||||||
errorCode = pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction, pageFunc, progressBarFunc,
|
errorCode = pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction, pageFunc, progressBarFunc,
|
||||||
noButton, waitInfoFunc,
|
noButton, waitInfoFunc,
|
||||||
busyInfoFunc, cancelButtonFunc);
|
busyInfoFunc, cancelButtonFunc);
|
||||||
m_serverController->disconnectFromHost(m_installCredentials);
|
|
||||||
|
|
||||||
if (errorCode == ErrorCode::NoError) {
|
if (errorCode == ErrorCode::NoError) {
|
||||||
if (!isServerCreated) {
|
if (!isServerCreated) {
|
||||||
QJsonObject server;
|
QJsonObject server;
|
||||||
|
@ -534,7 +532,6 @@ ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, bool &
|
||||||
|
|
||||||
QMap<DockerContainer, QJsonObject> installedContainers;
|
QMap<DockerContainer, QJsonObject> installedContainers;
|
||||||
ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(credentials, installedContainers);
|
ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(credentials, installedContainers);
|
||||||
m_serverController->disconnectFromHost(credentials);
|
|
||||||
if (errorCode != ErrorCode::NoError) {
|
if (errorCode != ErrorCode::NoError) {
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -372,8 +372,6 @@ void VpnConnection::connectToVpn(int serverIndex,
|
||||||
|
|
||||||
createProtocolConnections();
|
createProtocolConnections();
|
||||||
|
|
||||||
m_serverController->disconnectFromHost(credentials);
|
|
||||||
|
|
||||||
e = m_vpnProtocol.data()->start();
|
e = m_vpnProtocol.data()->start();
|
||||||
if (e) emit VpnProtocol::Error;
|
if (e) emit VpnProtocol::Error;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue