Merge pull request #41159 from azat/load-balancing-fix

Fix stack-use-after-return in GetPriorityForLoadBalancing::getPriorityFunc()
This commit is contained in:
Kruglov Pavel 2022-09-10 15:11:31 +02:00 committed by GitHub
commit 2ca5846595
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,7 +16,7 @@ std::function<size_t(size_t index)> GetPriorityForLoadBalancing::getPriorityFunc
case LoadBalancing::NEAREST_HOSTNAME:
if (hostname_differences.empty())
throw Exception(ErrorCodes::LOGICAL_ERROR, "It's a bug: hostname_differences is not initialized");
get_priority = [&](size_t i) { return hostname_differences[i]; };
get_priority = [this](size_t i) { return hostname_differences[i]; };
break;
case LoadBalancing::IN_ORDER:
get_priority = [](size_t i) { return i; };
@ -36,7 +36,7 @@ std::function<size_t(size_t index)> GetPriorityForLoadBalancing::getPriorityFunc
* last_used = 3 -> get_priority: 4 3 0 1 2
* ...
* */
get_priority = [&](size_t i)
get_priority = [this, pool_size](size_t i)
{
++i;
return i < last_used ? pool_size - i : i - last_used;