eclipse-lsp4j / lsp4j

A Java implementation of the language server protocol intended to be consumed by tools and language servers implemented in Java.
https://eclipse.org/lsp4j
Other
613 stars 145 forks source link

Cancel pendings requests if remote is shutdowned #639

Closed ses1112 closed 2 years ago

ses1112 commented 2 years ago

I am unsure if it is an issue or wrong usage of this module.

In the class RemoteEndpoint all requests are put in the sentRequestMap and a CompletableFuture is returned (Line 156 e.g.).

I have the problem, that in my application future.get() is called. But if now the remote is shutdowned, this Future will never be finished and my applications hungs.

Is this the expected behavior or is this a bug / not implemented feature? Is there an event where I can listen, if the remote is not reachable?

pisv commented 2 years ago

Generally speaking, there is no way for LSP4J to monitor if the remote is not reachable, because it simply does not know what the remote actually is: the remote is abstracted away by input/output streams in LSP4J and launching/connecting to the remote is beyond the scope of LSP4J by design.

In general, you should never call Future.get() without timeout when interacting with remote services.

You might also want to consider implementing a monitor of the state of the remote in order to relaunch/reconnect to it if the remote quits unexpectedly/becomes unreachable.

See https://github.com/lxtk-org/lxtk/blob/master/org.lxtk/src/org/lxtk/client/AbstractLanguageClientController.java for an example of how this can be done in a language client (LXTK is a client-side framework built on top of LSP4J).

ses1112 commented 2 years ago

Thanks for this answer, this helps a lot. I understand this expected behaviour of LSP4J.

pisv commented 2 years ago

@ses1112 Thank you for the feedback!