Skip to content

Commit cf19355

Browse files
committed
Another attempt at fixing busyReconcile flag
1 parent 6328c43 commit cf19355

File tree

2 files changed

+11
-17
lines changed
  • headless-services

2 files changed

+11
-17
lines changed

headless-services/commons/commons-language-server/src/main/java/org/springframework/ide/vscode/commons/languageserver/util/SimpleLanguageServer.java

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
import java.util.Collection;
1919
import java.util.Collections;
2020
import java.util.HashMap;
21+
import java.util.HashSet;
2122
import java.util.LinkedHashSet;
2223
import java.util.List;
2324
import java.util.Map;
2425
import java.util.Optional;
26+
import java.util.Set;
2527
import java.util.UUID;
2628
import java.util.concurrent.Callable;
2729
import java.util.concurrent.CompletableFuture;
@@ -600,7 +602,7 @@ public synchronized SimpleWorkspaceService getWorkspaceService() {
600602
* in a burst. Rather than execute the same request repeatedly we can avoid queuing
601603
* up more requests if the previous request has not yet been started.
602604
*/
603-
private Map<String, CompletableFuture<Void>> reconcileRequests = new ConcurrentHashMap<>();
605+
private Set<String> reconcileRequests = Collections.synchronizedSet(new HashSet<>());
604606

605607
private DiagnosticSeverityProvider severityProvider = DiagnosticSeverityProvider.DEFAULT;
606608

@@ -616,21 +618,14 @@ public void validateWith(TextDocumentIdentifier docId, IReconcileEngine engine)
616618
return;
617619
}
618620

619-
if (reconcileRequests.isEmpty()) {
620-
busyReconcile = new CompletableFuture<>();
621-
}
622-
623621
String uri = docId.getUri();
624-
CompletableFuture<Void> newFuture = new CompletableFuture<Void>();
625-
CompletableFuture<Void> oldFuture = reconcileRequests.putIfAbsent(uri, newFuture);
626-
if (oldFuture != null && oldFuture != newFuture) {
622+
if (!reconcileRequests.add(uri)) {
627623
log.debug("Reconcile skipped {}", uri);
628624
return;
629625
}
630-
631-
CompletableFuture<Void> reconcileSession = oldFuture == null ? newFuture : oldFuture;
632626
// Log.debug("Reconciling BUSY");
633627

628+
CompletableFuture<Void> currentSession = this.busyReconcile = new CompletableFuture<>();
634629
// Avoid running in the same thread as lsp4j as it can result
635630
// in long "hangs" for slow reconcile providers
636631
Mono<?> mono = props.getReconcileDelay() > 0
@@ -710,10 +705,7 @@ public void accept(ReconcileProblem problem) {
710705
return Mono.empty();
711706
})
712707
.doFinally(ignore -> {
713-
reconcileSession.complete(null);
714-
if (reconcileRequests.isEmpty()) {
715-
busyReconcile.complete(null);
716-
}
708+
currentSession.complete(null);
717709
// Log.debug("Reconciler DONE : "+this.busyReconcile.isDone());
718710
})
719711
.subscribe();

headless-services/concourse-language-server/src/test/java/org/springframework/ide/vscode/concourse/ConcourseEditorTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2016, 2019 Pivotal, Inc.
2+
* Copyright (c) 2016, 2022 Pivotal, Inc.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v1.0
55
* which accompanies this distribution, and is available at
@@ -4806,14 +4806,16 @@ public void taskWithYamlParams() throws Exception {
48064806

48074807
@Test public void reconcilerRaceCondition() throws Exception {
48084808
SynchronizationPoint reconcilerThreadStart = harness.reconcilerThreadStart();
4809+
System.out.println("Reconcile thread started");
48094810
Editor editor = harness.newEditor("garbage");
4810-
4811-
reconcilerThreadStart.reached(); // Blocks until the reconciler thread is reached.
4811+
System.out.println("Editor created");
48124812
try {
48134813
String editorContents = editor.getRawText();
48144814
for (int i = 0; i < 4; i++) {
4815+
System.out.println("Perfroming change: " + i);
48154816
editorContents = "\n" +editorContents;
48164817
editor.setText(editorContents);
4818+
System.out.println("Text changed: " + i);
48174819
}
48184820
} finally {
48194821
reconcilerThreadStart.unblock();

0 commit comments

Comments
 (0)