From 148d4e7e432181d6c9700d56383c082e87f74fee Mon Sep 17 00:00:00 2001 From: mirsal Date: Mon, 25 Nov 2024 04:04:43 +0000 Subject: [PATCH] matrix: Panic when the message-passing channel overflows --- src/matrix.rs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/matrix.rs b/src/matrix.rs index 4bbd864..7c88556 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -32,6 +32,8 @@ use tokio::{ sync::broadcast }; +use tracing::info; + async fn on_stripped_state_member( room_member: StrippedRoomMemberEvent, client: Client, @@ -97,18 +99,24 @@ pub async fn login_and_sync( loop { tokio::select! { Ok(_) = client.sync(settings.clone()) => return Ok(()), - Ok((msg, rooms)) = rx.recv() => { + recv = rx.recv() => match recv { + Ok((msg, rooms)) => { - let msg = &msg.clone(); - for r in rooms { - let room = client.join_room_by_id(<&RoomId>::try_from(r.as_str()) - .expect("invalid room ID") - ).await.expect(format!("Failed to join room {}", r).as_str()); + let msg = &msg.clone(); + for r in rooms { + info!("Joining room {}", r); + let room = client.join_room_by_id(<&RoomId>::try_from(r.as_str()) + .expect("invalid room ID") + ).await.expect(format!("Failed to join room {}", r).as_str()); - room.send(RoomMessageEventContent::text_html(msg.clone(), msg)).await - .expect("Failed to send matrix event"); + info!("Posting to room {}", r); + room.send(RoomMessageEventContent::text_html(msg.clone(), msg)).await + .expect("Failed to send matrix event"); + } + }, + Err(e) => { + panic!("Broadcast channel is lagging: {e:?}"); } - } } }