feat: announce disconnection upon deadlock detection

This commit is contained in:
2026-06-12 20:29:50 -04:00
parent c7300a9e6d
commit fa0093d582
3 changed files with 32 additions and 7 deletions

1
Cargo.lock generated
View File

@@ -1783,6 +1783,7 @@ dependencies = [
"opendal", "opendal",
"opus2", "opus2",
"patricia_tree 0.10.1", "patricia_tree 0.10.1",
"rayon",
"rhai", "rhai",
"rustls 0.23.40", "rustls 0.23.40",
"secrecy 0.10.3", "secrecy 0.10.3",

View File

@@ -56,6 +56,7 @@ opendal = { git = "https://github.com/apache/opendal", rev = "ecf840b04afd2be109
] } ] }
opus2 = "0.4.0" opus2 = "0.4.0"
patricia_tree = "0.10.1" patricia_tree = "0.10.1"
rayon = "1.12"
rhai = { version = "1.23.6", features = ["sync"] } rhai = { version = "1.23.6", features = ["sync"] }
rustls = "0.23" rustls = "0.23"
secrecy = { version = "0.10.3", features = ["serde"] } secrecy = { version = "0.10.3", features = ["serde"] }

View File

@@ -4,6 +4,7 @@ use fomo_reducer::{
RecordingManager, RenderManager, State, Storage, UserManager, VCsSender, all_commands, command, RecordingManager, RenderManager, State, Storage, UserManager, VCsSender, all_commands, command,
heat_seek, initialize_vcs, update_vcs, heat_seek, initialize_vcs, update_vcs,
}; };
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use secrecy::{ExposeSecret, SecretString}; use secrecy::{ExposeSecret, SecretString};
use snafu::{OptionExt, ResultExt, Snafu}; use snafu::{OptionExt, ResultExt, Snafu};
use songbird::{Config, Songbird, driver::DecodeConfig, shards::TwilightMap}; use songbird::{Config, Songbird, driver::DecodeConfig, shards::TwilightMap};
@@ -342,14 +343,36 @@ async fn main() -> Result<(), MainError> {
let (mut watchdog_tx, mut watchdog_rx) = let (mut watchdog_tx, mut watchdog_rx) =
futures::channel::mpsc::channel(watchdog_channel_size.get()); futures::channel::mpsc::channel(watchdog_channel_size.get());
std::thread::spawn(move || { std::thread::spawn({
loop { let discord_voice_channel_corresponding_text_channel =
if watchdog_tx.try_send(()).is_err() { discord_voice_channel_corresponding_text_channel.clone();
tracing::error!("tokio runtime deadlocked"); let discord_client = discord_client.clone();
std::process::exit(1); let vcs_watcher = vcs_sender.subscribe();
}
std::thread::sleep(watchdog_frequency); move || {
loop {
if watchdog_tx.try_send(()).is_err() {
tracing::error!("tokio runtime deadlocked");
vcs_watcher.borrow().par_iter().for_each(|(&guild_id, vcs_in_guild)| {
if let Some(&voice_channel_id) = vcs_in_guild.get_left_for(&discord_user_id) {
let text_channel_id =
discord_voice_channel_corresponding_text_channel
.get(&guild_id)
.and_then(|guild_mappings| {
guild_mappings.get_right_for(&voice_channel_id).copied()
})
.unwrap_or(voice_channel_id);
let _ = futures::executor::block_on(discord_client.create_message(text_channel_id).content("so sorry I died, I'm in purgatory now, I don't like it here.\nbut I will be back in 5-20 minutes (even if it says I'm still there, I'm not currently recording and will be disconnected soon before later reconnecting and announcing recording again)").into_future());
}
});
std::process::exit(1);
}
std::thread::sleep(watchdog_frequency);
}
} }
}); });