Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5e1de553 authored by Ken Chen's avatar Ken Chen
Browse files

Set global limiter from INT_MAX to 2500 by default

Although the global limiter is currently pushed by server, many OEM
devices do not login to the Google account to get the update before
auto testing. This commit set the default value to 2500 in module code.
This value is safe as google server has pushed the same value four
months ago and no issue was reported.

From statistical data, the issue this commit tries to fix happens only
in OEM labs with extreme conditions. The issue is not observed in the
field. So this is a fix for OEM lab testing only.

Bug: 291016548
Test: atest
Change-Id: If8d7ac9474e6682eb18659547ae7beca8f03a8f6
parent b7667e4b
Loading
Loading
Loading
Loading
+4 −5
Original line number Diff line number Diff line
@@ -70,20 +70,19 @@ using std::span;

namespace android {

using netdutils::MAX_QUERIES_IN_TOTAL;
using netdutils::MAX_QUERIES_PER_UID;
using netdutils::ResponseCode;
using netdutils::Stopwatch;

namespace net {
namespace {

// Limits the number of outstanding DNS queries by client UID.
constexpr int MAX_QUERIES_PER_UID = 256;

android::netdutils::OperationLimiter<uid_t> queryLimiter(MAX_QUERIES_PER_UID);

bool startQueryLimiter(uid_t uid) {
    const int globalLimit =
            android::net::Experiments::getInstance()->getFlag("max_queries_global", INT_MAX);
    const int globalLimit = android::net::Experiments::getInstance()->getFlag("max_queries_global",
                                                                              MAX_QUERIES_IN_TOTAL);
    return queryLimiter.start(uid, globalLimit);
}

+7 −2
Original line number Diff line number Diff line
@@ -28,6 +28,11 @@
namespace android {
namespace netdutils {

// Limits the number of outstanding DNS queries by client UID.
constexpr int MAX_QUERIES_PER_UID = 256;
// Limits the total number of outstanding DNS queries.
constexpr int MAX_QUERIES_IN_TOTAL = 2500;

// Tracks the number of operations in progress on behalf of a particular key or
// ID, rejecting further attempts to start new operations after a configurable
// limit has been reached.
@@ -56,11 +61,11 @@ class OperationLimiter {
    //
    // Note: each successful start(key) must be matched by exactly one call to
    // finish(key).
    bool start(KeyType key, int globalLimit = INT_MAX) EXCLUDES(mMutex) {
    bool start(KeyType key, int globalLimit = MAX_QUERIES_IN_TOTAL) EXCLUDES(mMutex) {
        std::lock_guard lock(mMutex);
        if (globalLimit < mLimitPerKey) {
            LOG(ERROR) << "Misconfiguration on max_queries_global " << globalLimit;
            globalLimit = INT_MAX;
            globalLimit = MAX_QUERIES_IN_TOTAL;
        }
        if (mGlobalCounter >= globalLimit) {
            // Oh, no!