Skip to content

Commit

Permalink
eth websocket: avoid locking control message sender and clone it instead
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocynicys committed Jun 17, 2024
1 parent 3798a29 commit a394c6a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mm2src/coins/eth/web3_transport/websocket_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct WebsocketTransport {

#[derive(Clone, Debug)]
struct ControllerChannel {
tx: Arc<AsyncMutex<UnboundedSender<ControllerMessage>>>,
tx: UnboundedSender<ControllerMessage>,
rx: Arc<AsyncMutex<UnboundedReceiver<ControllerMessage>>>,
}

Expand Down Expand Up @@ -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(())),
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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::<Vec<u8>>();

Expand Down

0 comments on commit a394c6a

Please sign in to comment.