dispose only when server got fully initialized, otherwise the shutdown hangs forever

This commit is contained in:
Martin Lippert
2019-08-20 15:17:34 +02:00
parent 89ee405fdd
commit 577901c8a1

View File

@@ -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