Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do we need to cancel listener on exit? #770

Closed
tdroxler opened this issue Nov 1, 2023 · 4 comments
Closed

Do we need to cancel listener on exit? #770

tdroxler opened this issue Nov 1, 2023 · 4 comments

Comments

@tdroxler
Copy link

tdroxler commented Nov 1, 2023

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
Copy link
Contributor

pisv commented Nov 1, 2023

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.

public boolean cancel(boolean mayInterruptIfRunning) {
if (mayInterruptIfRunning && messageProducer instanceof Closeable) {
try {
((Closeable) messageProducer).close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return result.cancel(mayInterruptIfRunning);
}

HTH

@pisv
Copy link
Contributor

pisv commented Nov 1, 2023

See also #585.

@tdroxler
Copy link
Author

tdroxler commented Nov 1, 2023

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
Copy link
Contributor

pisv commented Nov 1, 2023

LGTM 👍

tdroxler added a commit to alephium/ralph-lsp that referenced this issue Nov 1, 2023
As suggested by the `lsp4j` team: eclipse-lsp4j/lsp4j#770
@pisv pisv closed this as completed Nov 2, 2023
pisv added a commit that referenced this issue Dec 17, 2023
Updated documentation based on questions asked in #775 and #770.
pisv added a commit that referenced this issue Dec 20, 2023
Updated documentation based on questions asked in #775 and #770.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants