Skip to content
This repository was archived by the owner on Jun 17, 2025. It is now read-only.

Commit ba71105

Browse files
committed
Wipe out parking_lot
1 parent c2ca598 commit ba71105

File tree

42 files changed

+980
-667
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+980
-667
lines changed

Cargo.lock

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ serde_json = "1"
8787
systemstat = "0.2"
8888
num-format = "0.4"
8989
async-trait = "0.1"
90-
parking_lot = "0.12"
9190
unic-langid = "0.9"
9291
dasp_signal = "0.11"
9392
serde_derive = "1"
@@ -112,7 +111,7 @@ audiopus_sys = { version = "0.2", features = ["static"] }
112111
tokio-metrics = { version = "0.4", features = ["rt"] }
113112
async-tempfile = { version = "0.7", features = ["uuid"] }
114113
dasp_interpolate = { version = "0.11", features = ["linear"] }
115-
tokio = { version = "1", features = ["parking_lot", "signal", "rt-multi-thread"] }
114+
tokio = { version = "1", features = ["signal", "rt-multi-thread"] }
116115
reqwest = { version = "0.12", default-features = false, features = ["json", "rustls-tls"] }
117116
sqlx = { version = "0.8", features = ["postgres", "macros", "migrate", "runtime-tokio-rustls", "time"] }
118117

scripty_audio_handler/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ songbird.workspace = true
2020
serenity.workspace = true
2121
backtrace.workspace = true
2222
async-trait.workspace = true
23-
parking_lot.workspace = true
2423

2524
scripty_db = { path = "../scripty_db" }
2625
scripty_stt = { path = "../scripty_stt" }

scripty_audio_handler/src/audio_handler.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ use std::{
22
collections::VecDeque,
33
sync::{
44
Arc,
5+
RwLock,
56
atomic::{AtomicBool, AtomicU8, Ordering},
67
},
78
};
89

910
use ahash::RandomState;
1011
use dashmap::{DashMap, DashSet};
11-
use parking_lot::RwLock;
1212
use scripty_automod::types::AutomodServerConfig;
1313
use scripty_data_type::{CallDeath, get_data};
1414
use scripty_integrations::kiai::KiaiApiClient;
@@ -225,8 +225,20 @@ impl AudioHandler {
225225
self.kiai_enabled
226226
.store(guild_res.kiai_enabled, Ordering::Relaxed);
227227

228-
std::mem::swap(&mut *self.language.write(), &mut guild_res.language);
229-
*self.transcribe_only_role.write() = guild_res
228+
std::mem::swap(
229+
&mut *self.language.write().unwrap_or_else(|poisoned| {
230+
warn!(%self.guild_id, "language was poisoned");
231+
poisoned.into_inner()
232+
}),
233+
&mut guild_res.language,
234+
);
235+
*self
236+
.transcribe_only_role
237+
.write()
238+
.unwrap_or_else(|poisoned| {
239+
warn!(%self.guild_id, "language was poisoned");
240+
poisoned.into_inner()
241+
}) = guild_res
230242
.transcript_only_role
231243
.map(|x| RoleId::new(x as u64));
232244

@@ -244,7 +256,10 @@ impl EventHandler for AudioHandler {
244256
Arc::clone(&self.ssrc_state),
245257
self.seen_users.clone(),
246258
self.guild_id,
247-
*self.transcribe_only_role.read(),
259+
*self.transcribe_only_role.read().unwrap_or_else(|poisoned| {
260+
warn!("transcribe only role is poisoned");
261+
poisoned.into_inner()
262+
}),
248263
)),
249264
EventContext::VoiceTick(voice_data) => tokio::spawn(voice_tick(VoiceTickContext {
250265
voice_data: voice_data.clone(),

scripty_audio_handler/src/events/client_disconnect.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,15 @@ pub async fn client_disconnect(
6363
&& ssrc_state.active_user_set.len() < max_users
6464
{
6565
debug!(?ssrc, "there is space for another active user");
66-
if let Some(next) = ssrc_state.next_user_list.write().pop_front() {
66+
if let Some(next) = ssrc_state
67+
.next_user_list
68+
.write()
69+
.unwrap_or_else(|poisoned| {
70+
warn!("next user list is poisoned");
71+
poisoned.into_inner()
72+
})
73+
.pop_front()
74+
{
6775
debug!(?ssrc, "inserting new user into map");
6876
ssrc_state.active_user_set.insert(next);
6977
}
@@ -81,7 +89,12 @@ pub async fn client_disconnect(
8189
}
8290

8391
if let Some(transcript_results) = transcript_results {
84-
let mut transcript_results = transcript_results.write();
85-
transcript_results.push(format!("[{}] - event: disconnected", username));
92+
transcript_results
93+
.write()
94+
.unwrap_or_else(|poisoned| {
95+
warn!("transcript results are poisoned");
96+
poisoned.into_inner()
97+
})
98+
.push(format!("[{}] - event: disconnected", username));
8699
}
87100
}

scripty_audio_handler/src/events/driver_disconnect.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,16 @@ pub async fn driver_disconnect(
148148

149149
// send all users the results of their transcriptions
150150
if let (Some(transcript_results), Some(seen_users)) = (transcript_results, seen_users) {
151-
let final_text_output = transcript_results.read().join("\n");
151+
let final_text_output = transcript_results
152+
.read()
153+
.unwrap_or_else(|poisoned| {
154+
warn!(
155+
%guild_id,
156+
"transcript results poisoned, may be inconsistent"
157+
);
158+
poisoned.into_inner()
159+
})
160+
.join("\n");
152161
let attachment = CreateAttachment::bytes(final_text_output.into_bytes(), "transcript.txt");
153162
let message = CreateMessage::new().add_file(attachment.clone()).content(
154163
"This transcript was automatically sent to all users who spoke in the voice chat.",

scripty_audio_handler/src/events/voice_tick.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ use std::{
22
borrow::Cow,
33
sync::{
44
Arc,
5+
RwLock,
56
atomic::{AtomicBool, Ordering},
67
},
78
time::Instant,
89
};
910

1011
use ahash::RandomState;
1112
use dashmap::DashSet;
12-
use parking_lot::RwLock;
1313
use scripty_automod::types::{AutomodRuleAction, AutomodServerConfig};
1414
use scripty_integrations::kiai::{KiaiApiClient, KiaiPostVirtualMessage};
1515
use scripty_metrics::Metrics;
@@ -172,7 +172,13 @@ async fn handle_silent_speakers<'a>(
172172
};
173173

174174
// finalize the stream
175-
let lang = language.read().clone();
175+
let lang = language
176+
.read()
177+
.unwrap_or_else(|poisoned| {
178+
warn!(%guild_id, "language is poisoned");
179+
poisoned.into_inner()
180+
})
181+
.clone();
176182
let _typing = thread_id
177183
.map_or_else(|| channel_id.widen(), ThreadId::widen)
178184
.start_typing(ctx.http.clone());
@@ -288,7 +294,13 @@ async fn handle_silent_speakers<'a>(
288294
let username = &user_details.0;
289295
format!("[{}]: {}", username, final_result)
290296
};
291-
transcript_results.write().push(fmt_transcript);
297+
transcript_results
298+
.write()
299+
.unwrap_or_else(|poisoned| {
300+
warn!(%guild_id, "transcript results are poisoned");
301+
poisoned.into_inner()
302+
})
303+
.push(fmt_transcript);
292304
}
293305
}
294306

scripty_audio_handler/src/lib.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(clippy::unwrap_used, clippy::expect_used)]
12
#![feature(let_chains)]
23
#[macro_use]
34
extern crate tracing;
@@ -40,13 +41,16 @@ pub async fn get_voice_channel_id(guild_id: GuildId) -> Option<ChannelId> {
4041
}
4142

4243
pub fn set_songbird(sb: Arc<Songbird>) {
43-
SONGBIRD
44-
.set(sb)
45-
.expect("should not call set_songbird more than once");
44+
if SONGBIRD.set(sb).is_err() {
45+
warn!("set_songbird was called more than once");
46+
}
4647
}
4748

4849
pub fn get_songbird() -> Arc<Songbird> {
49-
SONGBIRD.get().expect("songbird not registered").clone()
50+
match SONGBIRD.get() {
51+
Some(sb) => sb.clone(),
52+
None => panic!("you must set get_songbird before calling get_songbird"),
53+
}
5054
}
5155

5256
static AUTO_LEAVE_TASKS: OnceCell<DashMap<GuildId, Sender<()>, ahash::RandomState>> =
@@ -110,6 +114,15 @@ pub fn get_internal_state(guild_id: &GuildId) -> Option<InternalSsrcStateDetails
110114
.collect(),
111115
ssrcs_actively_speaking_this_tick: v.ssrc_speaking_set.iter().map(|x| *x).collect(),
112116
actively_transcribed_ssrcs: v.active_user_set.iter().map(|x| *x).collect(),
113-
next_ssrcs: v.next_user_list.read().iter().copied().collect(),
117+
next_ssrcs: v
118+
.next_user_list
119+
.read()
120+
.unwrap_or_else(|poisoned| {
121+
warn!("next ssrc list is poisoned");
122+
poisoned.into_inner()
123+
})
124+
.iter()
125+
.copied()
126+
.collect(),
114127
})
115128
}

scripty_audio_handler/src/types.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
use std::{collections::VecDeque, sync::Arc};
1+
use std::{
2+
collections::VecDeque,
3+
sync::{Arc, RwLock},
4+
};
25

36
use ahash::RandomState;
47
use dashmap::{DashMap, DashSet};
5-
use parking_lot::RwLock;
68
use scripty_data_storage::VoiceIngest;
79
use scripty_stt::Stream;
810

scripty_bot/src/lib.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,25 @@ pub async fn entrypoint() {
2020
// fetch the config
2121
let cfg = scripty_config::get_config();
2222

23-
// initialize the blocked entity list
24-
info!("fetching blocked entities");
25-
scripty_bot_utils::entity_block::init_blocked()
26-
.await
27-
.expect("failed to init blocked entities");
28-
2923
// initialize the framework
24+
info!("loading framework");
3025
let framework = FrameworkBuilder::default()
3126
.options(framework_opts::get_framework_opts())
3227
.build();
28+
info!("setting global data");
3329
let data = Arc::new(Data::new());
3430
if CLIENT_DATA.set(data.clone()).is_err() {
3531
unreachable!("client data set more than once: bug?")
3632
}
3733

34+
info!("initializing songbird");
3835
let songbird = scripty_audio_handler::Songbird::serenity_from_config(
3936
scripty_audio_handler::get_songbird_config(),
4037
);
4138
scripty_audio_handler::set_songbird(songbird.clone());
4239

40+
info!("initializing HTTP client");
4341
let token = Token::from_str(&cfg.tokens.discord).expect("failed to parse token");
44-
4542
let mut http = serenity::http::HttpBuilder::new(token.clone());
4643
if let Some(proxy) = &cfg.proxy {
4744
http = http.proxy(proxy).ratelimiter_disabled(true);
@@ -51,6 +48,7 @@ pub async fn entrypoint() {
5148
ratelimiter.set_ratelimit_callback(Box::new(handler::ratelimit));
5249
}
5350

51+
info!("building serenity client");
5452
let mut client =
5553
ClientBuilder::new_with_http(token, Arc::new(http), framework_opts::get_gateway_intents())
5654
.compression(TransportCompression::None)
@@ -68,5 +66,6 @@ pub async fn entrypoint() {
6866
.set(client.shard_manager.runners.clone())
6967
.expect("no other task should set shard manager");
7068

69+
info!("starting scripty");
7170
client.start_autosharded().await.expect("failed to run bot");
7271
}

0 commit comments

Comments
 (0)