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

Commit 229fedcb authored by Mike Yu's avatar Mike Yu
Browse files

Make DohFrontend::clearQueries() synchronous

Sending a DNS query right after DohFrontend::clearQueries() is
commonly seen in PrivateDnsDohTest. However, it has a race issue
because frontend_stats_clear_queries() is asynchronous. Some
PrivateDnsDohTest tests are flaky due to that.

This change ensures that DohFrontend::clearQueries() returns after
the query count is reset.

Fix: 211362650
Test: Ran PrivateDnsDohTest.PreferIpv6 1000 times
Change-Id: I537c44b2015075130100e19279070c3e1ff698d3
parent 03a274f8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -366,6 +366,7 @@ async fn worker_thread(params: WorkerParams) -> Result<()> {
                }
            }
            Some(command) = command_rx.recv() => {
                debug!("ControlCommand: {:?}", command);
                match command {
                    ControlCommand::Stats {resp} => {
                        let stats = Stats {
+8 −0
Original line number Diff line number Diff line
@@ -97,6 +97,14 @@ void DohFrontend::clearQueries() {
    std::lock_guard guard(mMutex);
    if (mRustDoh) {
        frontend_stats_clear_queries(mRustDoh);

        // Because frontend_stats_clear_queries() is asynchronous, query the stat here to ensure
        // that mRustDoh reset the query count before clearQueries() returns.
        rust::Stats stats;
        rust::frontend_stats(mRustDoh, &stats);
        if (stats.queries_received != 0) {
            LOG(ERROR) << "queries_received is not 0";
        }
    }
}