Skip to content

Commit

Permalink
fix: prevent deadlock when resetting
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx committed Nov 29, 2024
1 parent dae4bc3 commit 8e6d093
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::fmt::{Debug, Formatter};
use std::iter::once;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, OnceLock, RwLock};

use eyre::{ensure, eyre, Context, Result};
use indexmap::{IndexMap, IndexSet};
use itertools::Itertools;
use once_cell::sync::{Lazy, OnceCell};
use rayon::prelude::*;
pub use settings::Settings;
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::fmt::{Debug, Formatter};
use std::iter::once;
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex, OnceLock, RwLock};
use std::time::Duration;
use walkdir::WalkDir;

use crate::backend::ABackend;
Expand All @@ -26,7 +26,7 @@ use crate::toolset::{
install_state, ToolRequestSet, ToolRequestSetBuilder, ToolVersion, Toolset, ToolsetBuilder,
};
use crate::ui::style;
use crate::{backend, dirs, env, file, lockfile, registry, runtime_symlinks, shims};
use crate::{backend, dirs, env, file, lockfile, registry, runtime_symlinks, shims, timeout};

pub mod config_file;
pub mod env_directive;
Expand Down Expand Up @@ -1036,13 +1036,21 @@ pub fn rebuild_shims_and_runtime_symlinks(new_versions: &[ToolVersion]) -> Resul
}

fn reset() {
install_state::reset();
backend::reset();
Settings::reset(None);
_CONFIG.write().unwrap().take();
*GLOBAL_CONFIG_FILES.lock().unwrap() = None;
*SYSTEM_CONFIG_FILES.lock().unwrap() = None;
GLOB_RESULTS.lock().unwrap().clear()
if let Err(err) = timeout::run_with_timeout(
|| {
install_state::reset();
backend::reset();
Settings::reset(None);
_CONFIG.write().unwrap().take();
*GLOBAL_CONFIG_FILES.lock().unwrap() = None;
*SYSTEM_CONFIG_FILES.lock().unwrap() = None;
GLOB_RESULTS.lock().unwrap().clear();
Ok(())
},
Duration::from_secs(5),
) {
error!("reset: {err}");
}
}

#[cfg(test)]
Expand Down

0 comments on commit 8e6d093

Please sign in to comment.