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
582 stars 141 forks source link

Do we need to cancel `listener` on `exit`? #770

Closed tdroxler closed 9 months ago

tdroxler commented 9 months ago

Hi everyone,

quick question, I'm starting my server with the startListening function and get back the Future[Void]. When my server receive the exit notification (after the obvious shutdown), do I need to cancel or clean in any other way my listnener (the Future[Void])?

Thx

pisv commented 9 months ago

Hi @tdroxler,

You need to call cancel(true) on the future to close the StreamMessageProducer, which will break the loop in the StreamMessageProducer.listen method.

https://github.com/eclipse-lsp4j/lsp4j/blob/3c98376797b96922689af963b8403431135f0f35/org.eclipse.lsp4j.jsonrpc/src/main/java/org/eclipse/lsp4j/jsonrpc/json/ConcurrentMessageProcessor.java#L69-L78

HTH

pisv commented 9 months ago

See also #585.

tdroxler commented 9 months ago

Thx for your quick answer, I guess I'll go with something like (pseudo code and scala):

  override def exit(): Unit = {
    server.listener.cancel(true)
    if(server.shutdownReceived) {
      System.exit(0)
    } else {
      System.exit(1)
    }
  }

checking the shutdownReceived to follow the exit specs

pisv commented 9 months ago

LGTM 👍