From 69be6eccac02470979614fdc2f7e2a3fa41b5613 Mon Sep 17 00:00:00 2001 From: Haitao Feng Date: Fri, 9 Oct 2026 01:32:20 -0700 Subject: [PATCH 1/7] Track in-flight analysis jobs per dispatch, not per hash The in-flight trackers were keyed by job hash, which is the same for every job on the same file. When a newer job for a file was dispatched while an older, cancelled one was still running, both shared one entry, and whichever finished first removed it. has_work() then reported no work while the newer job still ran, so the server ended its analysis progress early. dml-builtins.dml is hit by this on every device: each analysed import re-requests it, cancelling the running job. dfa exported on the early progress end and failed with "No device analyses found", because builtins, its imports, and so the device analysis had not been done. Key the trackers by an id assigned when the job is dispatched, and look up in-flight device jobs by hash among the values. Signed-off-by: Jonatan Waern --- src/actions/analysis_queue.rs | 69 ++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/src/actions/analysis_queue.rs b/src/actions/analysis_queue.rs index 65ce3797..fc59e1ac 100644 --- a/src/actions/analysis_queue.rs +++ b/src/actions/analysis_queue.rs @@ -33,9 +33,16 @@ use crate::server::ServerToHandle; use crate::logging::{info, debug, trace, error}; use crossbeam::channel; -// Maps in-process device jobs the timestamps of their dependencies -type InFlightDeviceJobTracker = HashMap)>; -type InFlightIsolatedJobTracker = HashMap; +// In-flight jobs are keyed by a per-dispatch id rather than by job hash, since +// several jobs with the same hash can be in flight at once (a cancelled job +// keeps running until it notices) and each must only remove its own entry. +type InFlightJobId = u64; +// Maps in-process device jobs to their hash, device, and the timestamps of +// their dependencies +type InFlightDeviceJobTracker = HashMap)>; +type InFlightIsolatedJobTracker = HashMap; // Queue up analysis tasks and execute them on the same thread (this is slower // than executing in parallel, but allows us to skip indexing tasks). pub struct AnalysisQueue { @@ -125,29 +132,21 @@ impl AnalysisQueue { device_analysis_options: DeviceAnalysisJobOptions) -> bool { match DeviceAnalysisJob::new(tracking_token, storage, bases, device, device_analysis_options) { Ok(newjob) => { - if let Some((_, previous_bases)) = self.device_tracker - .lock().unwrap() - .get(&newjob.hash) { - let mut newer_bases = false; - for base in &newjob.bases { - // If any base is missing or newer, - // the job is ok to go - if let Some(old_base_timestamp) = - previous_bases.get(&base.stored.path) { - if !timestamp_is_newer(base.timestamp, - *old_base_timestamp) { - continue; - } - } - newer_bases = true; - break; - } - if !newer_bases { - debug!("Skipped enqueueing device analysis job of \ - {:?}, no new dependencies", device); - return false; - } - } + // Skip if an in-flight job already covers these bases, + // i.e. no base is missing from it or newer than in it + let covered = self.device_tracker.lock().unwrap().values() + .filter(|(hash, _, _)| *hash == newjob.hash) + .any(|(_, _, previous_bases)| newjob.bases.iter().all( + |base| previous_bases.get(&base.stored.path) + .is_some_and(|old_base_timestamp| + !timestamp_is_newer( + base.timestamp, + *old_base_timestamp)))); + if covered { + debug!("Skipped enqueueing device analysis job of \ + {:?}, no new dependencies", device); + return false; + } debug!("Enqueued device analysis job of {:?}", device); self.enqueue(newjob.into()); true @@ -178,11 +177,14 @@ impl AnalysisQueue { queue: Arc>>, device_tracker: Arc>, isolated_tracker: Arc>) { + let mut next_job_id: InFlightJobId = 0; loop { if no_more_work.load(std::sync::atomic::Ordering::SeqCst) { thread::park(); continue; } + let job_id = next_job_id; + next_job_id += 1; let job = { let mut queue = queue.lock().unwrap(); if queue.is_empty() { @@ -195,15 +197,16 @@ impl AnalysisQueue { match queue.first() { Some(QueuedJob::DeviceAnalysisJob(job)) => { device_tracker.lock().unwrap().insert( - job.hash, - (job.root.path.clone(), + job_id, + (job.hash, + job.root.path.clone(), job.bases.iter().map( |base|(base.stored.path.clone(), base.timestamp)).collect())); }, Some(QueuedJob::IsolatedAnalysisJob(job)) => { isolated_tracker.lock().unwrap() - .insert(job.hash, job.path.clone()); + .insert(job_id, job.path.clone()); }, _ => (), } @@ -226,10 +229,9 @@ impl AnalysisQueue { Some(QueuedJob::IsolatedAnalysisJob(job)) => { thread::spawn({ let iso_tracker = Arc::clone(&isolated_tracker); - let hash = job.hash; move ||{ job.process(); - iso_tracker.lock().unwrap().remove(&hash); + iso_tracker.lock().unwrap().remove(&job_id); }}); }, Some(QueuedJob::FileLinterJob(job)) => { @@ -238,10 +240,9 @@ impl AnalysisQueue { Some(QueuedJob::DeviceAnalysisJob(job)) => { thread::spawn({ let dev_tracker = Arc::clone(&device_tracker); - let hash = job.hash; move ||{ job.process(); - dev_tracker.lock().unwrap().remove(&hash); + dev_tracker.lock().unwrap().remove(&job_id); }}); }, Some(QueuedJob::Sentinel) => { @@ -339,7 +340,7 @@ impl AnalysisQueue { } { let device_lock = self.device_tracker.lock().unwrap(); - for (path, _) in device_lock.values() { + for (_, path, _) in device_lock.values() { if paths.contains(path) { trace!("Detected there is still device \ work in-flight on {:?}", From a4384e8ed1ce54075bce43b324280db08e986a50 Mon Sep 17 00:00:00 2001 From: Haitao Feng Date: Fri, 9 Oct 2026 01:32:26 -0700 Subject: [PATCH 2/7] Report device analysis before notifying it is done DeviceAnalysisJob sent DeviceAnalysisDone before sending the analysis itself. The server's handler for it updates the stored analyses, which could then run before the analysis was in the channel, leaving it unstored until some later update. An export right after the analysis progress ended could then find no device analysis. Send the analysis first, as isolated analysis jobs already do. Signed-off-by: Jonatan Waern --- src/actions/analysis_queue.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/actions/analysis_queue.rs b/src/actions/analysis_queue.rs index fc59e1ac..d9d5a785 100644 --- a/src/actions/analysis_queue.rs +++ b/src/actions/analysis_queue.rs @@ -569,11 +569,12 @@ impl DeviceAnalysisJob { self.token.status) { Ok(analysis) => { info!("Finished device analysis of {:?}", analysis.name); - self.notify.send(ServerToHandle::DeviceAnalysisDone( - analysis.path.clone())).ok(); + let path = analysis.path.clone(); self.report.send(TimestampedStorage::make_timestamped( self.timestamp, analysis)).ok(); + self.notify.send(ServerToHandle::DeviceAnalysisDone( + path)).ok(); }, // In general, an analysis shouldn't fail to be created Err(AnalysisError::VFSError(e)) => { From 3b12698d9cf77c5c4c1700cc3b0d24020c602de6 Mon Sep 17 00:00:00 2001 From: Haitao Feng Date: Fri, 9 Oct 2026 02:57:51 -0700 Subject: [PATCH 3/7] Wake the server loop when an analysis job exits The server ends its analysis progress at the top of its loop, once no message is pending and the queue has no work. Analysis jobs sent their done message before leaving the in-flight tracker, and cancelled jobs sent nothing at all. If the loop handled the last done message before the job left the tracker, or the last job to exit was a cancelled one, the loop blocked waiting for a message with the progress still open, and dfa waited for its end forever. Send a message once a job has left the tracker, so that the loop re-checks for remaining work, and re-check state waits on it. Signed-off-by: Jonatan Waern --- src/actions/analysis_queue.rs | 4 ++++ src/server/mod.rs | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/actions/analysis_queue.rs b/src/actions/analysis_queue.rs index d9d5a785..4b37a3c8 100644 --- a/src/actions/analysis_queue.rs +++ b/src/actions/analysis_queue.rs @@ -229,9 +229,11 @@ impl AnalysisQueue { Some(QueuedJob::IsolatedAnalysisJob(job)) => { thread::spawn({ let iso_tracker = Arc::clone(&isolated_tracker); + let notify = job.notify.clone(); move ||{ job.process(); iso_tracker.lock().unwrap().remove(&job_id); + notify.send(ServerToHandle::AnalysisJobExited).ok(); }}); }, Some(QueuedJob::FileLinterJob(job)) => { @@ -240,9 +242,11 @@ impl AnalysisQueue { Some(QueuedJob::DeviceAnalysisJob(job)) => { thread::spawn({ let dev_tracker = Arc::clone(&device_tracker); + let notify = job.notify.clone(); move ||{ job.process(); dev_tracker.lock().unwrap().remove(&job_id); + notify.send(ServerToHandle::AnalysisJobExited).ok(); }}); }, Some(QueuedJob::Sentinel) => { diff --git a/src/server/mod.rs b/src/server/mod.rs index f118491a..7aaef301 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -466,7 +466,15 @@ impl LsService { &importpath, Some(source), context, &self.output); } } - } + }, + // Sent after a job has left the in-flight trackers, finished + // or not, so that the loop gets to re-check whether there + // is any work left, and end the progress if not + ServerToHandle::AnalysisJobExited => { + if let ActionContext::Init(ctx) = &mut self.ctx { + ctx.check_state_waits(); + } + }, } } } @@ -652,6 +660,7 @@ pub enum ServerToHandle { DeviceAnalysisDone(CanonPath), LinterDone(CanonPath), AnalysisRequest(PathBuf, Option, CanonPath), + AnalysisJobExited, } // Indicates how the server should proceed. From 6960a258e6da3f6c6a7c87eee3e26c28cd482ca9 Mon Sep 17 00:00:00 2001 From: Haitao Feng Date: Fri, 9 Oct 2026 19:31:29 -0700 Subject: [PATCH 4/7] Test that a job stays in flight when an older one exits Two isolated analysis jobs on the same file are in flight at once. Each reports on its own rendezvous channel, so it blocks until the test receives from it, and the test decides the order in which they exit. Once the older job has exited, the queue must still report the newer one as in-flight work, and each exit must be signalled with AnalysisJobExited. With the trackers keyed by job hash, the older job's exit removes the newer job's entry and has_isolated_work() turns false. Without the exit message the test gets none from the older job. Signed-off-by: Jonatan Waern --- src/actions/analysis_queue.rs | 87 +++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/src/actions/analysis_queue.rs b/src/actions/analysis_queue.rs index 4b37a3c8..49249ca0 100644 --- a/src/actions/analysis_queue.rs +++ b/src/actions/analysis_queue.rs @@ -658,3 +658,90 @@ impl LinterJob { } } } + +#[cfg(test)] +mod tests { + use super::*; + use std::time::{Duration, Instant}; + use crate::concurrency::ConcurrentJob; + + const TIMEOUT: Duration = Duration::from_secs(10); + + fn wait_until(what: &str, cond: impl Fn() -> bool) { + let start = Instant::now(); + while !cond() { + assert!(start.elapsed() < TIMEOUT, + "timed out waiting until {}", what); + thread::sleep(Duration::from_millis(1)); + } + } + + fn no_isolated_job_queued(queue: &AnalysisQueue) -> bool { + !queue.queue.lock().unwrap().iter() + .any(|job| matches!(job, QueuedJob::IsolatedAnalysisJob(_))) + } + + fn expect(rx: &channel::Receiver, + what: &str, + pred: impl Fn(&ServerToHandle) -> bool) { + let message = rx.recv_timeout(TIMEOUT) + .unwrap_or_else(|e| panic!("no message for {}: {}", what, e)); + assert!(pred(&message), "expected {}, got {:?}", what, message); + } + + // Two isolated jobs on the same file are in flight at once. Each job + // sends on its own rendezvous channel, so it blocks until the test + // receives from it, and the test decides which job finishes first. + #[test] + fn job_stays_in_flight_when_an_older_job_on_its_file_exits() { + let dir = std::env::temp_dir().join( + format!("dls-analysis-queue-test-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let file = dir.join("dev.dml"); + std::fs::write(&file, "dml 1.4;\ndevice dev;\n").unwrap(); + let path = CanonPath::from_path_buf(file.clone()).unwrap(); + let paths: HashSet = std::iter::once(path.clone()).collect(); + + let queue = AnalysisQueue::init(Arc::new(AtomicBool::new(false))); + let vfs = Vfs::new(); + let (older_tx, older_rx) = channel::bounded(0); + let (newer_tx, newer_rx) = channel::bounded(0); + let mut storage = AnalysisStorage::init(older_tx); + + let (mut older_job, older_token) = ConcurrentJob::new(); + assert!(queue.enqueue_isolated_job(&mut storage, &vfs, None, + path.clone(), file.clone(), + older_token)); + wait_until("the older job is dispatched", + || no_isolated_job_queued(&queue)); + + storage.notify = newer_tx; + let (mut newer_job, newer_token) = ConcurrentJob::new(); + assert!(queue.enqueue_isolated_job(&mut storage, &vfs, None, + path.clone(), file.clone(), + newer_token)); + wait_until("the newer job is dispatched", + || no_isolated_job_queued(&queue)); + + expect(&older_rx, "the older job's analysis", + |m| matches!(m, ServerToHandle::IsolatedAnalysisDone(..))); + expect(&older_rx, "the older job's exit", + |m| *m == ServerToHandle::AnalysisJobExited); + // The newer job is still blocked sending its analysis + assert!(queue.has_isolated_work()); + assert!(queue.working_on_isolated_for_paths(&paths)); + assert!(queue.has_work()); + + expect(&newer_rx, "the newer job's analysis", + |m| matches!(m, ServerToHandle::IsolatedAnalysisDone(..))); + expect(&newer_rx, "the newer job's exit", + |m| *m == ServerToHandle::AnalysisJobExited); + assert!(!queue.has_isolated_work()); + assert!(!queue.working_on_isolated_for_paths(&paths)); + wait_until("the queue has no work", || !queue.has_work()); + + older_job.kill(); + newer_job.kill(); + std::fs::remove_dir_all(&dir).ok(); + } +} From 1672d1d1bd5176f75db5b60019ba1f587566e08e Mon Sep 17 00:00:00 2001 From: Jonatan Waern Date: Mon, 12 Oct 2026 10:10:17 +0200 Subject: [PATCH 5/7] Refactor job.process to return the value to notify The jobs use it for nothing else, and this ensures we always notify _something_ regardless of how a job exits Signed-off-by: Jonatan Waern --- src/actions/analysis_queue.rs | 49 ++++++++++++++++------------------- src/actions/mod.rs | 10 ++++--- src/server/mod.rs | 5 ++-- 3 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/actions/analysis_queue.rs b/src/actions/analysis_queue.rs index 49249ca0..d4b320cf 100644 --- a/src/actions/analysis_queue.rs +++ b/src/actions/analysis_queue.rs @@ -58,7 +58,7 @@ pub struct AnalysisQueue { impl AnalysisQueue { // Create a new queue and start the worker thread. - pub fn init(no_more_work: Arc) -> AnalysisQueue { + pub fn init(no_more_work: Arc, server_notify: channel::Sender) -> AnalysisQueue { let queue = Arc::default(); let device_tracker = Arc::default(); let isolated_tracker = Arc::default(); @@ -69,12 +69,13 @@ impl AnalysisQueue { || AnalysisQueue::run_worker_thread(no_more_work, queue, device_tracker, - isolated_tracker) + isolated_tracker, + server_notify) }) .thread() .clone(); - AnalysisQueue { queue, worker_thread, device_tracker, isolated_tracker} + AnalysisQueue { queue, worker_thread, device_tracker, isolated_tracker } } pub fn enqueue_linter_job(&self, @@ -176,7 +177,8 @@ impl AnalysisQueue { fn run_worker_thread(no_more_work: Arc, queue: Arc>>, device_tracker: Arc>, - isolated_tracker: Arc>) { + isolated_tracker: Arc>, + server_notify: channel::Sender) { let mut next_job_id: InFlightJobId = 0; loop { if no_more_work.load(std::sync::atomic::Ordering::SeqCst) { @@ -229,24 +231,24 @@ impl AnalysisQueue { Some(QueuedJob::IsolatedAnalysisJob(job)) => { thread::spawn({ let iso_tracker = Arc::clone(&isolated_tracker); - let notify = job.notify.clone(); + let notify = server_notify.clone(); move ||{ - job.process(); + let res = job.process(); iso_tracker.lock().unwrap().remove(&job_id); - notify.send(ServerToHandle::AnalysisJobExited).ok(); + notify.send(res).ok(); }}); }, Some(QueuedJob::FileLinterJob(job)) => { - job.process() + server_notify.send(job.process()).ok(); }, Some(QueuedJob::DeviceAnalysisJob(job)) => { thread::spawn({ let dev_tracker = Arc::clone(&device_tracker); - let notify = job.notify.clone(); + let notify = server_notify.clone(); move ||{ - job.process(); + let res = job.process(); dev_tracker.lock().unwrap().remove(&job_id); - notify.send(ServerToHandle::AnalysisJobExited).ok(); + notify.send(res).ok(); }}); }, Some(QueuedJob::Sentinel) => { @@ -414,7 +416,6 @@ pub struct IsolatedAnalysisJob { client_path: PathBuf, timestamp: SystemTime, report: ResultChannel, - notify: channel::Sender, content: TextFile, context: Option, hash: u64, @@ -443,7 +444,6 @@ impl IsolatedAnalysisJob { client_path, timestamp, report: analysis.report.clone(), - notify: analysis.notify.clone(), hash, context, content, @@ -451,7 +451,7 @@ impl IsolatedAnalysisJob { }) } - fn process(self) { + fn process(self) -> ServerToHandle { info!("Started work on isolated analysis of {}", self.path.as_str()); match IsolatedAnalysis::new(&self.path, &self.client_path, @@ -467,11 +467,11 @@ impl IsolatedAnalysisJob { self.report.send(TimestampedStorage::make_timestamped( self.timestamp, analysis)).ok(); - self.notify.send(ServerToHandle::IsolatedAnalysisDone( + return ServerToHandle::IsolatedAnalysisDone( self.path.clone(), new_context, import_paths - )).ok(); + ); }, Err(AnalysisError::VFSError(e)) => { error!("Failed to create isolated analysis: {}", e); @@ -481,6 +481,7 @@ impl IsolatedAnalysisJob { debug!("Isolated analysis of {} was cancelled", self.path.as_str()); } } + ServerToHandle::AnalysisJobExited } } @@ -492,7 +493,6 @@ pub struct DeviceAnalysisJob { import_sources: HashMap, timestamp: SystemTime, report: ResultChannel, - notify: channel::Sender, hash: u64, token: JobToken, device_analysis_options: DeviceAnalysisJobOptions, @@ -553,14 +553,13 @@ impl DeviceAnalysisJob { timestamp, import_sources, report: analysis.report.clone(), - notify: analysis.notify.clone(), hash, token, device_analysis_options, }) } - fn process(self) { + fn process(self) -> ServerToHandle{ let root_path = self.root.path.clone(); info!("Started work on deviceanalysis of {:?}, depending on {:?}", self.root.path, @@ -577,8 +576,7 @@ impl DeviceAnalysisJob { self.report.send(TimestampedStorage::make_timestamped( self.timestamp, analysis)).ok(); - self.notify.send(ServerToHandle::DeviceAnalysisDone( - path)).ok(); + return ServerToHandle::DeviceAnalysisDone(path); }, // In general, an analysis shouldn't fail to be created Err(AnalysisError::VFSError(e)) => { @@ -589,6 +587,7 @@ impl DeviceAnalysisJob { debug!("Device analysis of {} was cancelled", root_path.as_str()); } } + ServerToHandle::AnalysisJobExited } } @@ -597,7 +596,6 @@ pub struct LinterJob { file: CanonPath, timestamp: SystemTime, report: ResultChannel, - notify: channel::Sender, content: TextFile, hash: u64, ast: IsolatedAnalysis, @@ -623,7 +621,6 @@ impl LinterJob { file: file.to_owned(), timestamp, report: analysis.report.clone(), - notify: analysis.notify.clone(), hash, ast: isolated_analysis.to_owned(), cfg, @@ -635,7 +632,7 @@ impl LinterJob { } } - fn process(self) { + fn process(self) -> ServerToHandle{ debug!("Started work on isolated linting of {:?}", self.file); match LinterAnalysis::new(&self.file, self.content, @@ -646,8 +643,7 @@ impl LinterJob { self.report.send(TimestampedStorage::make_timestamped( self.timestamp, analysis)).ok(); - self.notify.send(ServerToHandle::LinterDone( - self.file.clone())).ok(); + return ServerToHandle::LinterDone(self.file.clone()); }, Err(AnalysisError::VFSError(e)) => { error!("Failed to create isolated linter analysis: {}", e); @@ -656,6 +652,7 @@ impl LinterJob { debug!("Linter analysis of {} was cancelled", self.file.as_str()); } } + ServerToHandle::AnalysisJobExited } } diff --git a/src/actions/mod.rs b/src/actions/mod.rs index 3951d171..f8426211 100644 --- a/src/actions/mod.rs +++ b/src/actions/mod.rs @@ -378,11 +378,12 @@ impl InitActionContext { _client_supports_cmd_run: bool, ) -> InitActionContext { let shut_down = Arc::new(AtomicBool::new(false)); + let server_notify = analysis.as_ref().lock().unwrap().notify.clone(); InitActionContext { vfs, - analysis, analysis_queue: Arc::new(AnalysisQueue::init( - Arc::clone(&shut_down))), + Arc::clone(&shut_down), server_notify)), + analysis, current_notifier: Arc::default(), config, lint_config: Arc::new(Mutex::new(LintCfg::default())), @@ -413,11 +414,12 @@ impl InitActionContext { ) -> InitActionContext { let shut_down = Arc::new(AtomicBool::new(false)); let config = Arc::new(Mutex::new(Config::default())); - + let server_notify = analysis.as_ref().lock().unwrap().notify.clone(); + InitActionContext { analysis, vfs, - analysis_queue: Arc::new(AnalysisQueue::init(Arc::clone(&shut_down))), + analysis_queue: Arc::new(AnalysisQueue::init(Arc::clone(&shut_down), server_notify)), current_notifier: Arc::new(Mutex::new(None)), quiescent: Arc::new(AtomicBool::new(false)), workspace_roots: Arc::new(Mutex::new(Vec::new())), diff --git a/src/server/mod.rs b/src/server/mod.rs index 7aaef301..0859a099 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -467,9 +467,8 @@ impl LsService { } } }, - // Sent after a job has left the in-flight trackers, finished - // or not, so that the loop gets to re-check whether there - // is any work left, and end the progress if not + // Sent after a job has left the in-flight trackers, but without + // a result that must be handled ServerToHandle::AnalysisJobExited => { if let ActionContext::Init(ctx) = &mut self.ctx { ctx.check_state_waits(); From 6757a9ba95fc03de0830b2710d84bf4e65499295 Mon Sep 17 00:00:00 2001 From: Jonatan Waern Date: Mon, 12 Oct 2026 11:04:48 +0200 Subject: [PATCH 6/7] Fixup tests a bit Signed-off-by: Jonatan Waern --- src/actions/analysis_queue.rs | 73 +++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 20 deletions(-) diff --git a/src/actions/analysis_queue.rs b/src/actions/analysis_queue.rs index d4b320cf..f2d58408 100644 --- a/src/actions/analysis_queue.rs +++ b/src/actions/analysis_queue.rs @@ -678,6 +678,14 @@ mod tests { .any(|job| matches!(job, QueuedJob::IsolatedAnalysisJob(_))) } + // We just need some file for the canonpath, content is irrelevant + fn existing_file() -> PathBuf { + PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .join("src") + .join("actions") + .join("analysis_queue.rs") + } + fn expect(rx: &channel::Receiver, what: &str, pred: impl Fn(&ServerToHandle) -> bool) { @@ -687,23 +695,23 @@ mod tests { } // Two isolated jobs on the same file are in flight at once. Each job - // sends on its own rendezvous channel, so it blocks until the test - // receives from it, and the test decides which job finishes first. + // reports its result on its own rendezvous channel, so the test decides + // which job finishes first. #[test] fn job_stays_in_flight_when_an_older_job_on_its_file_exits() { - let dir = std::env::temp_dir().join( - format!("dls-analysis-queue-test-{}", std::process::id())); - std::fs::create_dir_all(&dir).unwrap(); - let file = dir.join("dev.dml"); - std::fs::write(&file, "dml 1.4;\ndevice dev;\n").unwrap(); + let file = existing_file(); let path = CanonPath::from_path_buf(file.clone()).unwrap(); let paths: HashSet = std::iter::once(path.clone()).collect(); - let queue = AnalysisQueue::init(Arc::new(AtomicBool::new(false))); + let (notify_tx, notify_rx) = channel::unbounded(); + let (older_report_tx, older_report_rx) = channel::bounded(0); + let (newer_report_tx, newer_report_rx) = channel::bounded(0); + let mut storage = AnalysisStorage::init(notify_tx.clone()); + storage.report = older_report_tx; + let queue = AnalysisQueue::init(Arc::new(AtomicBool::new(false)), + notify_tx); let vfs = Vfs::new(); - let (older_tx, older_rx) = channel::bounded(0); - let (newer_tx, newer_rx) = channel::bounded(0); - let mut storage = AnalysisStorage::init(older_tx); + vfs.set_file(&path, "dml 1.4;\ndevice dev;\n"); let (mut older_job, older_token) = ConcurrentJob::new(); assert!(queue.enqueue_isolated_job(&mut storage, &vfs, None, @@ -712,7 +720,7 @@ mod tests { wait_until("the older job is dispatched", || no_isolated_job_queued(&queue)); - storage.notify = newer_tx; + storage.report = newer_report_tx; let (mut newer_job, newer_token) = ConcurrentJob::new(); assert!(queue.enqueue_isolated_job(&mut storage, &vfs, None, path.clone(), file.clone(), @@ -720,25 +728,50 @@ mod tests { wait_until("the newer job is dispatched", || no_isolated_job_queued(&queue)); - expect(&older_rx, "the older job's analysis", + older_report_rx.recv_timeout(TIMEOUT) + .expect("no result from the older job"); + expect(¬ify_rx, "the older job's analysis", |m| matches!(m, ServerToHandle::IsolatedAnalysisDone(..))); - expect(&older_rx, "the older job's exit", - |m| *m == ServerToHandle::AnalysisJobExited); - // The newer job is still blocked sending its analysis + // The newer job is still blocked reporting its result. assert!(queue.has_isolated_work()); assert!(queue.working_on_isolated_for_paths(&paths)); assert!(queue.has_work()); - expect(&newer_rx, "the newer job's analysis", + newer_report_rx.recv_timeout(TIMEOUT) + .expect("no result from the newer job"); + expect(¬ify_rx, "the newer job's analysis", |m| matches!(m, ServerToHandle::IsolatedAnalysisDone(..))); - expect(&newer_rx, "the newer job's exit", - |m| *m == ServerToHandle::AnalysisJobExited); assert!(!queue.has_isolated_work()); assert!(!queue.working_on_isolated_for_paths(&paths)); wait_until("the queue has no work", || !queue.has_work()); older_job.kill(); newer_job.kill(); - std::fs::remove_dir_all(&dir).ok(); + } + + #[test] + fn early_cancelled_isolated_job_exits_and_leaves_no_work() { + let file = existing_file(); + let path = CanonPath::from_path_buf(file.clone()).unwrap(); + let paths: HashSet = std::iter::once(path.clone()).collect(); + + let (notify_tx, notify_rx) = channel::unbounded(); + let mut storage = AnalysisStorage::init(notify_tx.clone()); + let queue = AnalysisQueue::init(Arc::new(AtomicBool::new(false)), + notify_tx); + let vfs = Vfs::new(); + vfs.set_file(&path, "dml 1.4;\ndevice dev;\n"); + + let (mut job, token) = ConcurrentJob::new(); + job.kill(); + assert!(queue.enqueue_isolated_job(&mut storage, &vfs, None, + path, file, token)); + + expect(¬ify_rx, "the cancelled job's exit", + |m| *m == ServerToHandle::AnalysisJobExited); + assert!(storage.results.try_recv().is_err()); + assert!(!queue.has_isolated_work()); + assert!(!queue.working_on_isolated_for_paths(&paths)); + wait_until("the queue has no work", || !queue.has_work()); } } From 3c9df95d03a74a44fcbc1af0eab367e27acca5e0 Mon Sep 17 00:00:00 2001 From: Jonatan Waern Date: Tue, 13 Oct 2026 14:23:12 +0200 Subject: [PATCH 7/7] Update changelog Signed-off-by: Jonatan Waern --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d0a1fc1..3673d53c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - The DLS will now correctly report `param` declarations directly below a `#if` or `#else` block - The server will no longer send an LSP warning if dml-builtins is not found, instead relying on the client to perform this task - Fixed incorrect handling of explicit in-object constructs, correcting ranges of some error reports and detection of some linting errors +- Fixed an issue where the server would sometimes report `progress end` too early ## 0.9.20 - Made GetKnownContexts custom request not wait for analysis results by default, reducing the chances of overfilling workpool capacity while analysises are running.