Sfoglia il codice sorgente

use yield_now() in load_address() loop to prevent deadlock with other tasks.

narodnik 4 anni fa
parent
commit
ba7a0802db
2 ha cambiato i file con 6 aggiunte e 7 eliminazioni
  1. 1 4
      bin/ircd/src/main.rs
  2. 5 3
      src/net/sessions/outbound_session.rs

+ 1 - 4
bin/ircd/src/main.rs

@@ -17,7 +17,7 @@ use smol::Async;
 
 use drk::{
     net,
-    util::expand_path,
+    util::{expand_path, sleep},
     rpc::{
         jsonrpc::{
             error as jsonerr, request as jsonreq, response as jsonresp, send_raw_request,
@@ -109,14 +109,11 @@ async fn channel_loop(
     seen_privmsg_ids: SeenPrivMsgIdsPtr,
     executor: Arc<Executor<'_>>,
 ) -> Result<()> {
-    debug!("CHANNEL SUBS LOOP");
     let new_channel_sub = p2p.subscribe_channel().await;
 
     loop {
         let channel = new_channel_sub.receive().await?;
 
-        debug!("NEWCHANNEL");
-
         let protocol_privmsg = ProtocolPrivMsg::new(channel, sender.clone(), seen_privmsg_ids.clone(), p2p.clone()).await;
         protocol_privmsg.start(executor.clone()).await;
     }

+ 5 - 3
src/net/sessions/outbound_session.rs

@@ -1,5 +1,5 @@
 use async_executor::Executor;
-use async_std::sync::Mutex;
+use async_std::{sync::Mutex, task::yield_now};
 use log::*;
 use std::{
     net::SocketAddr,
@@ -111,9 +111,11 @@ impl OutboundSession {
     async fn load_address(&self, slot_number: u32) -> Result<SocketAddr> {
         let p2p = self.p2p();
         let hosts = p2p.hosts();
-        let inbound_addr = p2p.settings().inbound;
+        let self_inbound_addr = p2p.settings().external_addr;
 
         loop {
+            yield_now().await;
+
             let addr = hosts.load_single().await;
 
             if addr.is_none() {
@@ -122,7 +124,7 @@ impl OutboundSession {
             }
             let addr = addr.unwrap();
 
-            if Self::is_self_inbound(&addr, &inbound_addr) {
+            if Self::is_self_inbound(&addr, &self_inbound_addr) {
                 continue
             }