From a394c6aef70473e7be0707e0fe57d79f1952fb37 Mon Sep 17 00:00:00 2001 From: Omer Yacine Date: Mon, 17 Jun 2024 19:57:04 +0200 Subject: [PATCH] eth websocket: avoid locking control message sender and clone it instead --- mm2src/coins/eth/web3_transport/websocket_transport.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mm2src/coins/eth/web3_transport/websocket_transport.rs b/mm2src/coins/eth/web3_transport/websocket_transport.rs index 8e5fc81dc4..8b130c14fe 100644 --- a/mm2src/coins/eth/web3_transport/websocket_transport.rs +++ b/mm2src/coins/eth/web3_transport/websocket_transport.rs @@ -53,7 +53,7 @@ pub struct WebsocketTransport { #[derive(Clone, Debug)] struct ControllerChannel { - tx: Arc>>, + tx: UnboundedSender, rx: Arc>>, } @@ -88,7 +88,7 @@ impl WebsocketTransport { event_handlers, request_id: Arc::new(AtomicUsize::new(1)), controller_channel: ControllerChannel { - tx: Arc::new(AsyncMutex::new(req_tx)), + tx: req_tx, rx: Arc::new(AsyncMutex::new(req_rx)), }, connection_guard: Arc::new(AsyncMutex::new(())), @@ -309,7 +309,7 @@ impl WebsocketTransport { } pub(crate) async fn stop_connection_loop(&self) { - let mut tx = self.controller_channel.tx.lock().await; + let mut tx = self.controller_channel.tx.clone(); tx.send(ControllerMessage::Close) .await .expect("receiver channel must be alive"); @@ -353,7 +353,7 @@ async fn send_request( }; } - let mut tx = transport.controller_channel.tx.lock().await; + let mut tx = transport.controller_channel.tx.clone(); let (notification_sender, notification_receiver) = futures::channel::oneshot::channel::>();