fix: RwLock deadlock after game exits

This commit is contained in:
LynithDev 2024-07-28 12:30:45 +02:00
parent 246b5a3d6a
commit 54f6989b6e
5 changed files with 14 additions and 12 deletions

View file

@ -376,6 +376,7 @@ pub async fn update_playtime(path: &ClusterPath) -> crate::Result<()> {
cluster.meta.overall_played += recent_playtime;
cluster.meta.recently_played = 0;
}
drop(clusters);
State::sync().await?;

View file

@ -7,7 +7,7 @@ use crate::proxy::send::{init_ingress, send_ingress};
use crate::utils::http::{fetch_advanced, fetch_json};
use crate::utils::io::{self, IOError};
use crate::utils::java::{self, get_java_version, JavaVersion};
use crate::State;
use crate::{constants, State};
pub async fn filter_java_version(java_version: Option<u32>) -> crate::Result<Vec<JavaVersion>> {
let java = java::locate_java().await?;
@ -102,7 +102,7 @@ pub async fn install_java(java_version: u32) -> crate::Result<PathBuf> {
#[cfg(not(target_os = "macos"))]
{
base_path = base_path.join("bin").join(java::JAVA_BIN)
base_path = base_path.join("bin").join(constants::JAVA_BIN)
}
Ok(base_path)

View file

@ -167,8 +167,7 @@ pub async fn set_directory(new: PathBuf) -> crate::Result<()> {
tracing::trace!("re-resetting file watching system");
let mut file_watcher = crate::utils::watcher::initialize_watcher().await?;
state_write.clusters =
RwLock::new(Clusters::initialize(&state_write.directories, &mut file_watcher).await?);
state_write.clusters = RwLock::new(Clusters::initialize(&state_write.directories, &mut file_watcher).await?);
state_write.watcher = RwLock::new(file_watcher);
send_ingress(&ingress, 10.0, None).await?;

View file

@ -368,8 +368,6 @@ pub async fn launch_minecraft(
)
.current_dir(instance_path.clone());
println!("command: {:#?}", command);
// when cargo makes the DYLD_LIBRARY_PATH it breaks Minecraft
#[cfg(target_os = "macos")]
if std::env::var("CARGO").is_ok() {

View file

@ -582,9 +582,7 @@ impl Processor {
if let Err(err) = cluster::edit(&cluster_path, |cluster| {
cluster.meta.recently_played += update as u64;
async { Ok(()) }
})
.await
{
}).await {
tracing::warn!(
"failed to update playtime for cluster {}: {}",
&cluster_path,
@ -603,10 +601,16 @@ impl Processor {
}
});
{
let state = crate::State::get().await?;
tokio::spawn(async {
let state = match crate::State::get().await {
Ok(state) => state,
Err(err) => {
tracing::warn!("failed to get state: {}", err);
return;
}
};
let _ = state.discord_rpc.clear(true).await;
}
});
#[cfg(feature = "tauri")]
{