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

Commit 153b3fe1 authored by Mike Yu's avatar Mike Yu
Browse files

DoH: Increase the size of Network mpsc channel

Increase the channel size so that the DoH client can queue more
DNS requests before a DoH connection is established.

Apart from that, since the size of the queue is increased, it can
take more time to drain all the DNS requests out of the queue,
especially when DoH connections can't be established. This change
also add the check for expired DNS requests in Network object
before send them to Connection object.

Bug: 207301204
Test: cd packages/modules/DnsResolver && atest
Change-Id: Icfcbc7d389621cbbac23b5880907c26f1ab2f57f
parent 5d2a1071
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -283,6 +283,7 @@ impl H3Driver {
        // If the request has already timed out, don't issue it to the server.
        if let Some(expiry) = request.expiry {
            if BootTime::now() > expiry {
                warn!("Abandoning expired DNS request");
                return Ok(());
            }
        }
+9 −2
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ use crate::config::Config;
use crate::connection::Connection;
use crate::dispatcher::{QueryError, Response};
use crate::encoding;
use anyhow::{anyhow, Result};
use anyhow::{anyhow, bail, Result};
use std::sync::Arc;
use tokio::sync::{mpsc, watch};
use tokio::task;
@@ -90,7 +90,7 @@ async fn build_connection(
}

impl Driver {
    const MAX_BUFFERED_COMMANDS: usize = 10;
    const MAX_BUFFERED_COMMANDS: usize = 50;

    pub async fn new(
        info: ServerInfo,
@@ -175,6 +175,13 @@ impl Driver {
    }

    async fn send_query(&mut self, query: Query) -> Result<()> {
        // If the associated receiver has been closed, meaning that the request has already
        // timed out, just drop it. This check helps drain the channel quickly in the case
        // where the network is stalled.
        if query.response.is_closed() {
            bail!("Abandoning expired DNS request")
        }

        if !self.connection.wait_for_live().await {
            // Try reconnecting
            self.connection =
+2 −2
Original line number Diff line number Diff line
@@ -703,11 +703,11 @@ TEST_F(PrivateDnsDohTest, TemporaryConnectionStalled) {
// Note: This test is subject to MAX_BUFFERED_COMMANDS. If the value is changed, this test might
// need to be modified as well.
TEST_F(PrivateDnsDohTest, ExcessDnsRequests) {
    const int total_queries = 20;
    const int total_queries = 70;

    // The number is from MAX_BUFFERED_COMMANDS + 2 (one that will be queued in
    // connection mpsc channel; the other one that will get blocked at dispatcher sending channel).
    const int timeout_queries = 12;
    const int timeout_queries = 52;

    const int initial_max_idle_timeout_ms = 2000;
    ASSERT_TRUE(doh.stopServer());