fix(java): wait for the old compiler process to exit

Цей коміт міститься в:
l0ng-ai committed 2026-12-06 21:31:19 +08:00
1 джерело 36d3ed9901
коміт bdb383fa0b
2 files changed
+55 -7

No files matched your search

+37 -6
Переглянути файл
@@ -148,9 +148,16 @@ impl JavaBuildCoordinator {
// request takes the Eclipse project scheduling rule, draining a build
// already in progress before the borrower touches the same outputs.
for (writer, generation, roots) in paused {
let run = crate::jdtls::cancellable_wait(cancel, writer.wait_ready(Duration::from_secs(240))).await?;
let run = tokio::select! {
ready = crate::jdtls::cancellable_wait(cancel, writer.wait_ready(Duration::from_secs(240))) => ready?,
retired = self.wait_retired((writer.id, generation), cancel) => {
retired?;
continue;
}
};
let Some(run) = run.filter(|run| run.generation == generation) else {
if !writer.is_live(generation) {
self.wait_retired((writer.id, generation), cancel).await?;
continue;
}
return Err(IdeError::unavailable("Overlapping Java workspace is still starting; retry the build"));
@@ -161,21 +168,45 @@ impl JavaBuildCoordinator {
tokio::time::timeout(Duration::from_secs(240), writer.wait_java_ready(generation)),
)
.await?;
if !matches!(ready, Ok(true)) && writer.is_live(generation) {
if !matches!(ready, Ok(true)) {
if !writer.is_live(generation) {
self.wait_retired((writer.id, generation), cancel).await?;
continue;
}
return Err(IdeError::unavailable(
"Overlapping Java workspace is still importing; retry the build",
));
}
}
let result = crate::jdtls::cancellable_wait(cancel, drain(&run, &roots, Some(cancel.clone()))).await?;
if let Err(error) = result
&& writer.is_live(generation)
{
return Err(error);
if let Err(error) = result {
if writer.is_live(generation) {
return Err(error);
}
self.wait_retired((writer.id, generation), cancel).await?;
}
}
Ok(permit)
}
/// Stopping changes the server status before its JVM has released the
/// output files. Wait for reaping, not merely for the transport to close.
async fn wait_retired(&self, instance: Instance, cancel: &CancellationToken) -> IdeResult<()> {
let wait = async {
loop {
let changed = self.changed.notified();
tokio::pin!(changed);
changed.as_mut().enable();
if !self.state.lock().entries.iter().any(|entry| entry.instance == instance) {
return;
}
changed.await;
}
};
crate::jdtls::cancellable_wait(cancel, tokio::time::timeout(Duration::from_secs(240), wait))
.await?
.map_err(|_| IdeError::unavailable("Overlapping Java workspace has not stopped; retry the build"))
}
}
/// Query the project's classpaths under its Eclipse scheduling rule. An
+18 -1
Переглянути файл
@@ -3384,7 +3384,24 @@ async fn java_overlapping_windows_coordinate_autobuild_and_explicit_builds() {
.iter()
.all(|p| p["settings"]["java"]["autobuild"]["enabled"] == false)
);
parent.mgr.shutdown_all().await;
// Down is published before the JVM has exited. A child build must wait
// for the old writer to release the workspace, not just for that status.
let exit = Arc::new(Gate::default());
*primary.held.lock() = Some(("exit".into(), exit.clone()));
let shutdown = tokio::spawn({
let mgr = parent.mgr.clone();
async move { mgr.shutdown_all().await }
});
eventually(|| exit.entered()).await;
let mut build = tokio::spawn({
let (mgr, root) = (child.mgr.clone(), child.root.clone());
async move { mgr.java_build(&root, false, &Default::default()).await }
});
let early = tokio::time::timeout(Duration::from_millis(100), &mut build).await;
exit.open();
shutdown.await.unwrap();
assert!(early.is_err(), "the child must wait for the first writer to exit: {early:?}");
assert_eq!(build.await.unwrap().unwrap(), ide_lsp::jdtls::JavaBuildStatus::Succeeded);
eventually(|| {
secondary
.notified("workspace/didChangeConfiguration")