feat(ipc): Error handling for missing version in IPC handshake
This commit is contained in:
parent
77bee2ddf3
commit
7c30add2a1
2 changed files with 21 additions and 3 deletions
|
|
@ -112,12 +112,23 @@ void IpcServer::processMessage(QLocalSocket *clientSocket, const QString &messag
|
|||
}
|
||||
|
||||
if (const auto &command = parts.at(0); command == "hello") {
|
||||
if (parts.size() < 2) {
|
||||
LOG_ERR("%s ipc client hello missing version", m_typeName.constData());
|
||||
writeToClientSocket(clientSocket, "error=missing version");
|
||||
clientSocket->flush();
|
||||
clientSocket->disconnectFromServer();
|
||||
return;
|
||||
}
|
||||
|
||||
const auto versionId = QStringLiteral("%1+%2").arg(kVersion, kVersionGitSha);
|
||||
const auto clientVersion = parts.size() >= 2 ? parts.at(1) : QString();
|
||||
const auto clientVersion = parts.at(1);
|
||||
LOG_DEBUG("%s ipc server got hello message (version: %s)", m_typeName.constData(), versionId.toUtf8().constData());
|
||||
|
||||
if (clientVersion != versionId) {
|
||||
LOG_ERR("%s ipc client version mismatch (server: %s)", m_typeName.constData(), versionId.toUtf8().constData());
|
||||
LOG_ERR(
|
||||
"%s ipc client version mismatch (client: %s, server: %s)", m_typeName.constData(),
|
||||
clientVersion.toUtf8().constData(), versionId.toUtf8().constData()
|
||||
);
|
||||
writeToClientSocket(clientSocket, QStringLiteral("error=version mismatch, expected: %1").arg(versionId));
|
||||
clientSocket->flush();
|
||||
clientSocket->disconnectFromServer();
|
||||
|
|
|
|||
|
|
@ -175,8 +175,15 @@ void IpcClient::handleHandshakeMessage(const QStringList &parts)
|
|||
return;
|
||||
}
|
||||
|
||||
if (parts.size() < 2) {
|
||||
qCritical().noquote() << QStringLiteral("%1 ipc server hello missing version").arg(m_typeName);
|
||||
disconnectFromServer();
|
||||
Q_EMIT connectionFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
const auto versionId = QStringLiteral("%1+%2").arg(kVersion, kVersionGitSha);
|
||||
const auto serverVersion = parts.size() >= 2 ? parts.at(1) : QString();
|
||||
const auto serverVersion = parts.at(1);
|
||||
if (serverVersion != versionId) {
|
||||
qCritical().noquote(
|
||||
) << QStringLiteral("%1 ipc version mismatch (client: %2 , server: %3)").arg(m_typeName, versionId, serverVersion);
|
||||
|
|
|
|||
Loading…
Reference in a new issue