Skip to content

Commit

Permalink
SLLS-70 Prevent creation of engines after shutdown order
Browse files Browse the repository at this point in the history
  • Loading branch information
damien-urruty-sonarsource committed Apr 1, 2022
1 parent 8ae9f7b commit c68026d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/main/java/org/sonarsource/sonarlint/ls/EnginesFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import org.sonarsource.sonarlint.core.ConnectedSonarLintEngineImpl;
Expand Down Expand Up @@ -71,6 +72,7 @@ public class EnginesFactory {
private final NodeJsRuntime nodeJsRuntime;
private final ClientModulesProvider modulesProvider;
private final Collection<Path> extraAnalyzers;
private final AtomicReference<Boolean> shutdown = new AtomicReference<>(false);

public EnginesFactory(Collection<Path> standaloneAnalyzers, LanguageClientLogOutput globalLogOutput, NodeJsRuntime nodeJsRuntime, ClientModulesProvider modulesProvider,
Collection<Path> extraAnalyzers) {
Expand All @@ -82,6 +84,9 @@ public EnginesFactory(Collection<Path> standaloneAnalyzers, LanguageClientLogOut
}

public StandaloneSonarLintEngine createStandaloneEngine() {
if (shutdown.get().equals(true)) {
throw new IllegalStateException("Language server is shutting down, won't create engine");
}
LOG.debug("Starting standalone SonarLint engine...");
LOG.debug("Using {} analyzers", standaloneAnalyzers.size());

Expand Down Expand Up @@ -110,6 +115,9 @@ StandaloneSonarLintEngine newStandaloneEngine(StandaloneGlobalConfiguration conf
}

public ConnectedSonarLintEngine createConnectedEngine(String connectionId) {
if (shutdown.get().equals(true)) {
throw new IllegalStateException("Language server is shutting down, won't create engine");
}
var builder = ConnectedGlobalConfiguration.builder()
.setConnectionId(connectionId)
.setExtraProperties(prepareExtraProps())
Expand Down Expand Up @@ -158,4 +166,8 @@ public static Set<Language> getStandaloneLanguages() {
return EnumSet.copyOf(List.of(STANDALONE_LANGUAGES));
}

public void shutdown() {
shutdown.set(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ public CompletableFuture<Object> shutdown() {
List.<Runnable>of(
// start by not processing any more messages from the client
() -> Utils.shutdownAndAwait(threadPool, true),
// prevent creation of new engines
enginesFactory::shutdown,
analysisScheduler::shutdown,
branchManager::shutdown,
securityHotspotsHandlerServer::shutdown,
Expand Down

0 comments on commit c68026d

Please sign in to comment.