From 577901c8a1dab03f6e0186e0b0b3b4af5d618ea4 Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Tue, 20 Aug 2019 15:17:34 +0200 Subject: [PATCH] dispose only when server got fully initialized, otherwise the shutdown hangs forever --- .../ls/JavaProjectsServiceWithFallback.java | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/jdt/ls/JavaProjectsServiceWithFallback.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/jdt/ls/JavaProjectsServiceWithFallback.java index b502533f0..8ad76af2b 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/jdt/ls/JavaProjectsServiceWithFallback.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/jdt/ls/JavaProjectsServiceWithFallback.java @@ -79,24 +79,17 @@ public class JavaProjectsServiceWithFallback implements JavaProjectsService { this.mainServiceInitialized = this.server .onInitialized(main.initialize()) + .doOnSuccess((disposable) -> { + server.onShutdown(() -> { + disposable.dispose(); + }); + }) .doOnError(error -> { log.warn("JDT-based JavaProject service not available, will use fallback service", error); }) .toFuture(); - this.server.onShutdown(() -> { - try { - if (!mainServiceInitialized.isCompletedExceptionally()) { - // If classpath listener has been added successfully, remove it - mainServiceInitialized.thenAccept(Disposable::dispose).join(); - } - } catch (Exception e) { - // If completable future hasn't completed yet it might complete with exception to add classpath listener. - // Handle exception gracefully rather than failing LS process to terminate - log.error("", e); - } - } - ); + log.info("set fallback shutdown handler"); } @Override