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

Commit 5d2a1071 authored by Mike Yu's avatar Mike Yu
Browse files

DoH: Change Network to use try_send

As send() blocks until channel has capacity, Dispatcher gets blocked
at sending commands to a Network object if the Network's mpsc channel
has no capacity. This happens when there are excess DNS requests while
the connection has not been established. Therefore, change all the DoH
code to use try_send() that returns an error immediate if the channel
is full.

If a Network's mpsc channel has no capacity, DNS query threads that
called doh_query() with the associated net_id will get DOH_RESULT_CAN_NOT_SEND
error immediately. Since it's not a timeout error, they will try DoT.

Bug: 207301204
Test: cd packages/modules/DnsResolver && atest
Change-Id: I9575e6f410b8b552c07af15284b67b305ecce6b9
parent 4bdc8678
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -102,7 +102,7 @@ impl Network {
                .unwrap_or_else(|_| {
                    warn!("Query result listener went away before receiving a response")
                }),
            Status::Live => self.command_tx.send(Command::Query(query)).await?,
            Status::Live => self.command_tx.try_send(Command::Query(query))?,
        }
        Ok(())
    }
+2 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ struct Stats {
    uint32_t queries_received;
    /// The number of accumulated QUIC connections accepted.
    uint32_t connections_accepted;
    /// The number of QUIC connections alive.
    uint32_t alive_connections;
};

extern "C" {
+8 −0
Original line number Diff line number Diff line
@@ -222,6 +222,10 @@ impl Client {
    pub fn on_timeout(&mut self) {
        self.conn.on_timeout();
    }

    pub fn is_alive(&self) -> bool {
        self.conn.is_established() && !self.conn.is_closed()
    }
}

impl std::fmt::Debug for Client {
@@ -286,6 +290,10 @@ impl ClientMap {
        self.clients.iter_mut()
    }

    pub fn iter(&mut self) -> hash_map::Iter<ConnectionID, Client> {
        self.clients.iter()
    }

    pub fn len(&mut self) -> usize {
        self.clients.len()
    }
+5 −1
Original line number Diff line number Diff line
@@ -368,7 +368,11 @@ async fn worker_thread(params: WorkerParams) -> Result<()> {
            Some(command) = command_rx.recv() => {
                match command {
                    ControlCommand::Stats {resp} => {
                        let stats = Stats {queries_received, connections_accepted: clients.len() as u32};
                        let stats = Stats {
                            queries_received,
                            connections_accepted: clients.len() as u32,
                            alive_connections: clients.iter().filter(|(_, client)| client.is_alive()).count() as u32,
                        };
                        if let Err(e) = resp.send(stats) {
                            error!("Failed to send ControlCommand::Stats response: {:?}", e);
                        }
+1 −0
Original line number Diff line number Diff line
@@ -160,6 +160,7 @@ pub extern "C" fn frontend_stats(doh: &mut DohFrontend, out: &mut Stats) -> bool
        .map(|stats| {
            out.queries_received = stats.queries_received;
            out.connections_accepted = stats.connections_accepted;
            out.alive_connections = stats.alive_connections;
        })
        .or_else(logging_and_return_err)
        .is_ok()
Loading