From 7633e30b168e738bd85cd912838c9f2d4214ce6c Mon Sep 17 00:00:00 2001 From: stutxo <70952638+stutxo@users.noreply.github.com> Date: Sun, 16 Jun 2024 12:31:41 +0100 Subject: [PATCH 1/2] fix notifier --- node/connection/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/connection/src/lib.rs b/node/connection/src/lib.rs index 426b7c5..4ddc042 100644 --- a/node/connection/src/lib.rs +++ b/node/connection/src/lib.rs @@ -210,7 +210,7 @@ where if handle_received(writer, msg).await.is_err() { return Err("Message handling failure: Closing peer connection".into()); } else { - notifier.notified(); + notifier.notify_one(); } }, Ok(msg_bytes) = send_to_all_receiver.recv() => { From a9f93651f9df3002ff2c5ee0792f09d523001383 Mon Sep 17 00:00:00 2001 From: stutxo <70952638+stutxo@users.noreply.github.com> Date: Mon, 17 Jun 2024 14:41:32 +0100 Subject: [PATCH 2/2] update connection test --- node/connection/src/lib.rs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/node/connection/src/lib.rs b/node/connection/src/lib.rs index 4ddc042..83a2cc1 100644 --- a/node/connection/src/lib.rs +++ b/node/connection/src/lib.rs @@ -123,7 +123,6 @@ pub async fn start_listen( loop { // Asynchronously wait for an inbound TcpStream. log::info!("Starting accept"); - notifier.notify_one(); match listener.accept().await { Ok((stream, peer_address)) => { log::info!("Accepted connection from {:?}", peer_address); @@ -210,6 +209,7 @@ where if handle_received(writer, msg).await.is_err() { return Err("Message handling failure: Closing peer connection".into()); } else { + log::debug!("Message handled"); notifier.notify_one(); } }, @@ -356,29 +356,26 @@ mod tests { let (send_to_all_tx, send_to_all_rx) = broadcast::channel::(32); - let notify = Arc::new(Notify::new()); - let notify_listen_cloned = notify.clone(); - let notify_connect_cloned = notify.clone(); - tokio::spawn(async move { start_listen( - "localhost:6680".to_string(), + "127.0.0.1:6680".to_string(), listen_manager_cloned, 32, send_to_all_tx, - notify_listen_cloned, + Arc::new(Notify::new()), ) .await; }); - notify.notified().await; + let notify = Arc::new(Notify::new()); + let notify_clone = notify.clone(); let _ = connect( - "localhost:6680".to_string(), + "127.0.0.1:6680".to_string(), connect_manager_cloned, 32, send_to_all_rx, - notify_connect_cloned, + notify_clone, ) .await;