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

Commit 55514553 authored by Mike Yu's avatar Mike Yu Committed by Automerger Merge Worker
Browse files

Terminate private DNS validation threads if network is down am: 22432351

parents abe8686b 22432351
Loading
Loading
Loading
Loading
+11 −5
Original line number Diff line number Diff line
@@ -145,6 +145,9 @@ void PrivateDnsConfiguration::clear(unsigned netId) {
    std::lock_guard guard(mPrivateDnsLock);
    mPrivateDnsModes.erase(netId);
    mPrivateDnsTransports.erase(netId);

    // Notify the relevant private DNS validations, if they are waiting, to finish.
    mCv.notify_all();
}

base::Result<void> PrivateDnsConfiguration::requestValidation(unsigned netId,
@@ -224,14 +227,17 @@ void PrivateDnsConfiguration::startValidation(const ServerIdentity& identity, un
            const bool needs_reeval =
                    this->recordPrivateDnsValidation(identity, netId, success, isRevalidation);

            if (!needs_reeval) {
            if (!needs_reeval || !backoff.hasNextTimeout()) {
                break;
            }

            if (backoff.hasNextTimeout()) {
                // TODO: make the thread able to receive signals to shutdown early.
                std::this_thread::sleep_for(backoff.getNextTimeout());
            } else {
            std::unique_lock<std::mutex> cvGuard(mPrivateDnsLock);
            // If the timeout expired and the predicate still evaluates to false, wait_for returns
            // false.
            if (mCv.wait_for(cvGuard, backoff.getNextTimeout(),
                             [this, netId]() REQUIRES(mPrivateDnsLock) {
                                 return mPrivateDnsModes.find(netId) == mPrivateDnsModes.end();
                             })) {
                break;
            }
        }
+1 −0
Original line number Diff line number Diff line
@@ -185,6 +185,7 @@ class PrivateDnsConfiguration {
    PrivateDnsValidationObserver* mObserver GUARDED_BY(mPrivateDnsLock);

    DohDispatcher* mDohDispatcher;
    std::condition_variable mCv;

    friend class PrivateDnsConfigurationTest;