diff options
author | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2024-04-12 15:27:45 +0300 |
---|---|---|
committer | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2024-04-16 09:43:26 +0300 |
commit | 97eb1648cca2ff0d20d280263df2a70d1a6717d7 (patch) | |
tree | a59c04c492cb71bbb5ca0a2fd577bac756a465ea | |
parent | a962b314041cbd2a9d9eb34dc12b36cd66a9b53f (diff) |
Disconnect clients immediately on reservation expiration
After a reservation expiry event was sent, the associated client
application were disconnected only after the release request was
made and the server returned a response indicating success.
This missed cases where the network connectivity was temprorarily down
or request failed for some other reason. There could be also some
delay between performing the request, and receiving the response, so
clients could be using the reservation longer than the lease time
would allow.
Fix by disconnecting clients consuming a reservation to be released
as a first action when handling a reservation expiry.
Task-number: QLS-898
Pick-to: 3.0
Change-Id: Ie4f913024c1b163ee08d22b69d1acf2a32114a6e
Reviewed-by: Iikka Eklund <iikka.eklund@qt.io>
-rw-r--r-- | src/libs/qlicenseservice/licenser.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/libs/qlicenseservice/licenser.cpp b/src/libs/qlicenseservice/licenser.cpp index f87f3e5..24712c6 100644 --- a/src/libs/qlicenseservice/licenser.cpp +++ b/src/libs/qlicenseservice/licenser.cpp @@ -349,6 +349,10 @@ int Licenser::processReservation(ClientHandler *client, uint32_t delay) void Licenser::processRelease(Reservation *reservation, uint32_t delay) { + // Clients are disconnected immediately when the reservation expires, + // as the release request may not succeed in a timely manner + disconnectClientsForReservation(reservation); + const std::string reservationId = reservation->id(); if (m_state == DaemonState::BadConnection || m_state == DaemonState::Offline) { // No need to bother with the request if we already know there's no connection @@ -369,8 +373,10 @@ void Licenser::processRelease(Reservation *reservation, uint32_t delay) std::string reply; Status result = m_http->receive(requestId, reply); if (reply.empty() || result == Status::BAD_CONNECTION) { + // Something went wrong with the request, keep the reservation as we + // can try to remove it during next startup m_state = DaemonState::BadConnection; - return -1; // Something went wrong with the request + return -1; } if (serverIsBusy(reply)) { @@ -381,8 +387,7 @@ void Licenser::processRelease(Reservation *reservation, uint32_t delay) m_retryCounter->reset(); } - logDebug("Removing reservation with ID %s", reservationId.c_str()); - disconnectClientsForReservation(reservation); + logDebug("Released reservation with ID %s", reservationId.c_str()); removeReservation(reservation); return 0; @@ -701,6 +706,7 @@ void Licenser::disconnectClientsForReservation(Reservation *reservation) { for (const auto &client : m_clients) { if (client.second->reservationId() == reservation->id()) { + logDebug("Disconnecting client %d for reservation %s", client.first, reservation->id().c_str()); client.second->revokeCurrentReservation(); m_tcpServer->closeClientSocket(client.second->socketId()); } @@ -710,8 +716,10 @@ void Licenser::disconnectClientsForReservation(Reservation *reservation) void Licenser::resetClientsForReservation(Reservation *reservation) { for (const auto &client : m_clients) { - if (client.second->reservationId() == reservation->id()) + if (client.second->reservationId() == reservation->id()) { + logDebug("Removing reservation %s from client %d", reservation->id().c_str(), client.first); client.second->revokeCurrentReservation(); + } } } |