From 170c628ad1063c7355e8cb2385fc7f56843c69cf Mon Sep 17 00:00:00 2001 From: Hongli Lai Date: Sun, 10 Nov 2024 16:53:15 +0100 Subject: [PATCH] fixes --- .../Group/ProcessListManagement.cpp | 36 ++++++++++++------- .../Group/SessionManagement.cpp | 3 +- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp b/src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp index 120feb5eb1..5c17841a59 100644 --- a/src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp +++ b/src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp @@ -70,25 +70,30 @@ Group::findProcessWithStickySessionId(unsigned int id) const { * * - If the process with the given sticky session ID exists, then always * returns that process. Meaning that this process could be `!canBeRoutedTo()`. - * - If there is no process that be routed to, then returns nullptr. + * - If there is no process that can be routed to, then returns nullptr. */ Process * Group::findBestProcessPreferringStickySessionId(unsigned int id) const { Process *bestProcess = nullptr; ProcessList::const_iterator it; ProcessList::const_iterator end = enabledProcesses.end(); + for (it = enabledProcesses.begin(); it != end; it++) { Process *process = it->get(); if (process->getStickySessionId() == id) { return process; - } else if (!process->isTotallyBusy() && (bestProcess == nullptr || - process->generation > bestProcess->generation || - (process->generation == bestProcess->generation && process->spawnStartTime < bestProcess->spawnStartTime) || - (process->generation == bestProcess->generation && process->spawnStartTime == bestProcess->spawnStartTime && process->busyness() < bestProcess->busyness()) - )) { + } else if (!process->isTotallyBusy() + && ( + bestProcess == nullptr + || process->generation > bestProcess->generation + || (process->generation == bestProcess->generation && process->spawnStartTime < bestProcess->spawnStartTime) + || (process->generation == bestProcess->generation && process->spawnStartTime == bestProcess->spawnStartTime && process->busyness() < bestProcess->busyness()) + ) + ) { bestProcess = process; } } + return bestProcess; } @@ -97,7 +102,7 @@ Group::findBestProcessPreferringStickySessionId(unsigned int id) const { * At the moment, "best" is defined as the process with the highest generation, * lowest start time, and lowest busyness, in that order of priority. * - * If there is no process that be routed to, then returns nullptr. + * If there is no process that can be routed to, then returns nullptr. * * @post result != nullptr || result.canBeRoutedTo() */ @@ -110,17 +115,22 @@ Group::findBestProcess(const ProcessList &processes) const { Process *bestProcess = nullptr; ProcessList::const_iterator it; ProcessList::const_iterator end = processes.end(); + for (it = processes.begin(); it != end; it++) { - Process *process = (*it).get(); + Process *process = it->get(); - if (!process->isTotallyBusy() && (bestProcess == nullptr || - process->generation > bestProcess->generation || - (process->generation == bestProcess->generation && process->spawnStartTime < bestProcess->spawnStartTime) || - (process->generation == bestProcess->generation && process->spawnStartTime == bestProcess->spawnStartTime && process->busyness() < bestProcess->busyness()) - )) { + if (!process->isTotallyBusy() + && ( + bestProcess == nullptr + || process->generation > bestProcess->generation + || (process->generation == bestProcess->generation && process->spawnStartTime < bestProcess->spawnStartTime) + || (process->generation == bestProcess->generation && process->spawnStartTime == bestProcess->spawnStartTime && process->busyness() < bestProcess->busyness()) + ) + ) { bestProcess = process; } } + return bestProcess; } diff --git a/src/agent/Core/ApplicationPool/Group/SessionManagement.cpp b/src/agent/Core/ApplicationPool/Group/SessionManagement.cpp index 8bdccbbc03..0a7af88e0e 100644 --- a/src/agent/Core/ApplicationPool/Group/SessionManagement.cpp +++ b/src/agent/Core/ApplicationPool/Group/SessionManagement.cpp @@ -314,8 +314,7 @@ Group::get(const Options &newOptions, const GetCallback &callback, if (disablingCount > 0 && !restarting()) { Process *process = findBestProcess(disablingProcesses); - assert(process != NULL); - if (!process->isTotallyBusy()) { + if (process != nullptr && !process->isTotallyBusy()) { return newSession(process, newOptions.currentTime); } }