From c401222a84ef1a4a02f0cd4d88145a8e2a02a5fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Wed, 1 Apr 2020 15:33:27 +0100 Subject: [PATCH] Yielding tokio task upon creating loop/real traffic message (#166) --- nym-client/src/client/cover_traffic_stream.rs | 3 +++ nym-client/src/client/mod.rs | 4 +++- nym-client/src/client/real_traffic_stream.rs | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/nym-client/src/client/cover_traffic_stream.rs b/nym-client/src/client/cover_traffic_stream.rs index c0e4e8dc57..4c076cbb30 100644 --- a/nym-client/src/client/cover_traffic_stream.rs +++ b/nym-client/src/client/cover_traffic_stream.rs @@ -99,6 +99,9 @@ impl LoopCoverTrafficStream { self.mix_tx .unbounded_send(MixMessage::new(cover_message.0, cover_message.1)) .unwrap(); + // JS: due to identical logical structure to OutQueueControl::on_message(), this is also + // presumably required to prevent bugs in the future. Exact reason is still unknown to me. + tokio::task::yield_now().await; } async fn run(&mut self) { diff --git a/nym-client/src/client/mod.rs b/nym-client/src/client/mod.rs index f6596751ac..b009b7c7b8 100644 --- a/nym-client/src/client/mod.rs +++ b/nym-client/src/client/mod.rs @@ -345,6 +345,8 @@ impl NymClient { input_tx.clone(), ); self.input_tx = Some(input_tx); - self.receive_tx = Some(received_messages_buffer_output_tx) + self.receive_tx = Some(received_messages_buffer_output_tx); + + info!("Client startup finished!"); } } diff --git a/nym-client/src/client/real_traffic_stream.rs b/nym-client/src/client/real_traffic_stream.rs index 2e83196610..997f709438 100644 --- a/nym-client/src/client/real_traffic_stream.rs +++ b/nym-client/src/client/real_traffic_stream.rs @@ -127,6 +127,9 @@ impl OutQueueControl { self.mix_tx .unbounded_send(MixMessage::new(next_packet.0, next_packet.1)) .unwrap(); + // JS: Not entirely sure why or how it fixes stuff, but without the yield call, + // the UnboundedReceiver [of mix_rx] will not get a chance to read anything + tokio::task::yield_now().await; } pub(crate) async fn run_out_queue_control(mut self) {