Cleanup ConnectionManager

- Do not block starting the puppet processes while waiting for the reply
- Remove unnessecary connection.clear() from ConnectionManager::shutDown
  since this was already done in closeSocketsAndKillProcesses
- Remove Timers from ConnectionManager::closeSocketsAndKillProcesses
  since they leak memory and termination of the processes is done in
  QProcessUniquePointerDeleter
- Remove second deleteLater from QProcessUniquePointerDeleter since this
  is handled by the connection to the finished signal

Change-Id: If845ea44f483c5d3c646595ff9298bcdd3dfd59a
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Knud Dollereder
2022-02-08 12:59:50 +01:00
parent 8e3496a6ce
commit b9d59edeb1
5 changed files with 18 additions and 28 deletions

View File

@@ -53,17 +53,18 @@ void ConnectionManager::setUp(NodeInstanceServerInterface *nodeInstanceServerPro
{
BaseConnectionManager::setUp(nodeInstanceServerProxy, qrcMappingString, target, view);
m_localServer = std::make_unique<QLocalServer>();
QString socketToken(QUuid::createUuid().toString());
m_localServer->listen(socketToken);
m_localServer->setMaxPendingConnections(3);
PuppetCreator puppetCreator(target, view->model());
puppetCreator.setQrcMappingString(qrcMappingString);
puppetCreator.createQml2PuppetExecutableIfMissing();
for (Connection &connection : m_connections) {
QString socketToken(QUuid::createUuid().toString());
connection.localServer = std::make_unique<QLocalServer>();
connection.localServer->listen(socketToken);
connection.localServer->setMaxPendingConnections(1);
connection.qmlPuppetProcess = puppetCreator.createPuppetProcess(
connection.mode,
socketToken,
@@ -71,10 +72,11 @@ void ConnectionManager::setUp(NodeInstanceServerInterface *nodeInstanceServerPro
[&](int exitCode, QProcess::ExitStatus exitStatus) {
processFinished(exitCode, exitStatus, connection.name);
});
}
const int second = 1000;
const int second = 1000;
for (Connection &connection : m_connections) {
int waitConstant = 8 * second;
if (!connection.qmlPuppetProcess->waitForStarted(waitConstant)) {
closeSocketsAndKillProcesses();
showCannotConnectToPuppetWarningAndSwitchToEditMode();
@@ -84,11 +86,11 @@ void ConnectionManager::setUp(NodeInstanceServerInterface *nodeInstanceServerPro
waitConstant /= 2;
bool connectedToPuppet = true;
if (!m_localServer->hasPendingConnections())
connectedToPuppet = m_localServer->waitForNewConnection(waitConstant);
if (!connection.localServer->hasPendingConnections())
connectedToPuppet = connection.localServer->waitForNewConnection(waitConstant);
if (connectedToPuppet) {
connection.socket.reset(m_localServer->nextPendingConnection());
connection.socket.reset(connection.localServer->nextPendingConnection());
QObject::connect(connection.socket.get(), &QIODevice::readyRead, this, [&] {
readDataStream(connection);
});
@@ -97,9 +99,8 @@ void ConnectionManager::setUp(NodeInstanceServerInterface *nodeInstanceServerPro
showCannotConnectToPuppetWarningAndSwitchToEditMode();
return;
}
connection.localServer->close();
}
m_localServer->close();
}
void ConnectionManager::shutDown()
@@ -107,11 +108,6 @@ void ConnectionManager::shutDown()
BaseConnectionManager::shutDown();
closeSocketsAndKillProcesses();
m_localServer.reset();
for (Connection &connection : m_connections)
connection.clear();
}
void ConnectionManager::writeCommand(const QVariant &command)
@@ -150,11 +146,6 @@ void ConnectionManager::closeSocketsAndKillProcesses()
connection.socket->abort();
}
if (connection.qmlPuppetProcess) {
QTimer::singleShot(3000, connection.qmlPuppetProcess.get(), &QProcess::terminate);
QTimer::singleShot(6000, connection.qmlPuppetProcess.get(), &QProcess::kill);
}
connection.clear();
}
}

View File

@@ -70,8 +70,6 @@ private:
void closeSocketsAndKillProcesses();
private:
std::unique_ptr<QLocalServer> m_localServer;
std::vector<Connection> m_connections;
quint32 m_writeCommandCounter = 0;
};

View File

@@ -26,6 +26,7 @@
#include "connectionmanagerinterface.h"
#include <QLocalSocket>
#include <QLocalServer>
#include <QTimer>
namespace QmlDesigner {
@@ -45,6 +46,7 @@ void ConnectionManagerInterface::Connection::clear()
{
qmlPuppetProcess.reset();
socket.reset();
localServer.reset();
blockSize = 0;
lastReadCommandCounter = 0;
timer.reset();

View File

@@ -30,6 +30,7 @@
QT_BEGIN_NAMESPACE
class QLocalSocket;
class QLocalServer;
QT_END_NAMESPACE
namespace ProjectExplorer {
@@ -59,6 +60,7 @@ public:
QString mode;
QProcessUniquePointer qmlPuppetProcess;
std::unique_ptr<QLocalSocket> socket;
std::unique_ptr<QLocalServer> localServer;
quint32 blockSize = 0;
quint32 lastReadCommandCounter = 0;
std::unique_ptr<QTimer> timer;

View File

@@ -41,10 +41,7 @@ public:
QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
process,
&QProcess::deleteLater);
process->terminate();
process->deleteLater();
process->kill();
}
};