aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArttu Tarkiainen <arttu.tarkiainen@qt.io>2024-04-04 16:26:05 +0300
committerArttu Tarkiainen <arttu.tarkiainen@qt.io>2024-04-11 08:26:51 +0300
commit21d77299c6a7fb76aae7df6b74a2335fc179473c (patch)
tree0044377db05296f28aae12b9f5f5d73fea4506ff
parenta2a319ee4243d3fbbc4e0c4c2d1ac1fcbae2812c (diff)
Fix logic error on releasing a reservation which has connected clients
Reservation information is reset from clients without disconnecting, when renewal fails but the daemon may attempt a new reservation. Clients are disconnected on reservation release. The reservation information was reset from clients before the lookup for clients that needed disconnecting, meaning none were found. Fix by resetting the clients only just before disconnecting. Also move the disconnect and reset methods out of Licenser::removeReservation() as the previously used boolean parameter was not very clear. Pick-to: 3.0 Task-number: QLS-896 Change-Id: I38d16575d7e5099850d6f72176f6d0b6c5a8a5fc Reviewed-by: Iikka Eklund <iikka.eklund@qt.io>
-rw-r--r--src/libs/qlicenseservice/licenser.cpp15
-rw-r--r--src/libs/qlicenseservice/licenser.h2
2 files changed, 8 insertions, 9 deletions
diff --git a/src/libs/qlicenseservice/licenser.cpp b/src/libs/qlicenseservice/licenser.cpp
index 65c321e..7c0b996 100644
--- a/src/libs/qlicenseservice/licenser.cpp
+++ b/src/libs/qlicenseservice/licenser.cpp
@@ -373,6 +373,7 @@ void Licenser::processRelease(Reservation *reservation, uint32_t delay)
}
logDebug("Removing reservation with ID %s", reservationId.c_str());
+ disconnectClientsForReservation(reservation);
removeReservation(reservation);
return 0;
@@ -427,7 +428,8 @@ void Licenser::processRenewal(Reservation *reservation, uint32_t delay)
// and perform a new license request for all current consumers
logWarn("Could not renew reservation id: %s: invalid data.", reservationId.c_str());
- removeReservation(reservation, false);
+ resetClientsForReservation(reservation);
+ removeReservation(reservation);
for (const auto &client : m_clients) {
if (client.second->reservationId() == reservationId) {
logInfo("Attempting re-reservation for client id: %d", client.first);
@@ -689,8 +691,10 @@ ClientHandler *Licenser::getClient(uint16_t clientId)
void Licenser::disconnectClientsForReservation(Reservation *reservation)
{
for (const auto &client : m_clients) {
- if (client.second->reservationId() == reservation->id())
+ if (client.second->reservationId() == reservation->id()) {
+ client.second->revokeCurrentReservation();
m_tcpServer->closeClientSocket(client.second->socketId());
+ }
}
}
@@ -741,13 +745,8 @@ bool Licenser::getServerVersion()
return true;
}
-void Licenser::removeReservation(Reservation *reservation, bool disconnectClients)
+void Licenser::removeReservation(Reservation *reservation)
{
- resetClientsForReservation(reservation);
-
- if (disconnectClients)
- disconnectClientsForReservation(reservation);
-
License *license = reservation->license();
license->removeReservation(reservation->id());
diff --git a/src/libs/qlicenseservice/licenser.h b/src/libs/qlicenseservice/licenser.h
index a2486e4..40ec1c2 100644
--- a/src/libs/qlicenseservice/licenser.h
+++ b/src/libs/qlicenseservice/licenser.h
@@ -88,7 +88,7 @@ private:
std::string getDaemonVersion();
bool getServerVersion();
- void removeReservation(Reservation *reservation, bool disconnectClients = true);
+ void removeReservation(Reservation *reservation);
std::string getReservations(const std::string &user);
void releaseExpiredReservations();