summaryrefslogtreecommitdiff
path: root/cli/lsp/diagnostics.rs
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2021-01-26 10:55:04 +0100
committerGitHub <noreply@github.com>2021-01-26 10:55:04 +0100
commit2828690fc7bb510c3248dda7b1cda8793e789ca6 (patch)
tree96ca85ab8ae9a2d60679729cc161539c3900a386 /cli/lsp/diagnostics.rs
parent2823c02e434577393cf0575d4ad9116da1076b17 (diff)
fix(lsp): fix deadlocks, use one big mutex (#9271)
The LSP code had numerous places where competing threads could take out out locks in different orders, making it very prone to deadlocks. This commit sidesteps the entire issue by switching to a single lock. The above is a little white lie: the Sources struct still uses a mutex internally to avoid having to boil the ocean (because being honest about what it does involves changing all its methods to `&mut self` but that ripples out extensively...) I'll save that one for another day.
Diffstat (limited to 'cli/lsp/diagnostics.rs')
-rw-r--r--cli/lsp/diagnostics.rs9
1 files changed, 2 insertions, 7 deletions
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs
index a9dc843f4..1637249d6 100644
--- a/cli/lsp/diagnostics.rs
+++ b/cli/lsp/diagnostics.rs
@@ -9,7 +9,6 @@ use super::tsc;
use crate::diagnostics;
use crate::media_type::MediaType;
-use deno_core::error::custom_error;
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::ModuleSpecifier;
@@ -265,17 +264,13 @@ pub async fn generate_ts_diagnostics(
}
pub async fn generate_dependency_diagnostics(
- state_snapshot: StateSnapshot,
+ mut state_snapshot: StateSnapshot,
diagnostic_collection: DiagnosticCollection,
) -> Result<DiagnosticVec, AnyError> {
tokio::task::spawn_blocking(move || {
let mut diagnostics = Vec::new();
- let mut sources = if let Ok(sources) = state_snapshot.sources.lock() {
- sources
- } else {
- return Err(custom_error("Deadlock", "deadlock locking sources"));
- };
+ let sources = &mut state_snapshot.sources;
for specifier in state_snapshot.documents.open_specifiers() {
let version = state_snapshot.documents.version(specifier);
let current_version = diagnostic_collection.get_version(specifier);