From 62bcd1133ae5d6f7e33317430727ef96d164600d Mon Sep 17 00:00:00 2001 From: Wiebe Cazemier Date: Mon, 18 Nov 2024 21:42:16 +0100 Subject: [PATCH] Fix collecting disconnecting clients only on exit Collecting clients that were normally being disconnected in disconnectingClients was wrong and would cause the vector to grow very large. --- threaddata.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/threaddata.cpp b/threaddata.cpp index 59b860e..2581beb 100644 --- a/threaddata.cpp +++ b/threaddata.cpp @@ -712,8 +712,16 @@ void ThreadData::sendAllDisconnects() serverInitiatedDisconnect(c, ReasonCodes::ServerShuttingDown, ""); } - uint64_t one = 1; - check(write(disconnectingAllEventFd, &one, sizeof(uint64_t))); + auto queued_collect_disconnecting_clients = [clientsFound, this](){ + for (const std::shared_ptr &c : clientsFound) + { + this->disconnectingClients.push_back(c); + } + + uint64_t one = 1; + check(write(disconnectingAllEventFd, &one, sizeof(uint64_t))); + }; + addImmediateTask(queued_collect_disconnecting_clients); } void ThreadData::removeQueuedClients() @@ -1029,8 +1037,6 @@ void ThreadData::serverInitiatedDisconnect(const std::shared_ptr &client client->setDisconnectStage(DisconnectStage::Now); removeClientQueued(client); } - - disconnectingClients.push_back(client); }; addImmediateTask(f);