-
Notifications
You must be signed in to change notification settings - Fork 99
Gracefully exit the server #622
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
Conversation
|
Do you want a review on this yet? |
|
Yes, the this MR is ready for review, but the corresponding hls changes at haskell/haskell-language-server#4701 still need some more polishing. |
6ee37a0 to
3cf7ceb
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
@soulomoon I assume, you still want a review? 🙈 I mean, this is still ready for review, right? |
|
@fendor Yes, thanks for picking it up. If the general change looks good, I can resolve the conflict. |
fendor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, got some nitpicks and mostly documentation update requests.
Thank you for chasing this issue down, it is really quite annoying!
Should we perhaps add a Note [Handle Server exiting] or something like that?
- Track shutdown/exit separately and wait for sender to flush before exit - Make runServerWithHandles resilient to broken pipes and log truncated messages - Have runServerWith/ioLoop return proper exit codes based on shutdown state - Adjust processing to use sender wait action during shutdown and log exit - Fix functional test harness to assert zero exit code instead of ExitSuccess - Tidy minor CI workflow whitespace in format.yaml and nix.yaml
375ea8a to
df52cc0
Compare
Co-authored-by: fendor <fendor@users.noreply.github.com>
The main purpose of this patch is to fix the long standing broken pipe issue in hls, see haskell/haskell-language-server#1875. It accompanied with the hls fix haskell/haskell-language-server#4701
This pull request introduces several improvements to the LSP server's shutdown and exit handling. The changes ensure that output is properly flushed and errors are logged if the client disconnects unexpectedly, and that the server's sender thread is gracefully shut down. The shutdown and exit logic is now more explicit with new state tracking and barriers.
resExitbarrier toLanguageContextStateand anisExitingfunction to track when the server should exit, ensuring that the server stops processing messages after an exit notification is received. [1]clientOutto catch and logBrokenPipeerrors when sending output fails (e.g., if the client closes the output handle), including a truncated version of the outgoing message for debugging.withAsyncandraceto better manage the sender thread lifecycle and ensure clean shutdowns. [1]sendServerfunction to terminate after sending the shutdown response, preventing further messages from being sent after shutdown. Modified the main server loop and sender logic to wait for the sender thread to finish after shutdown, with a timeout and logging if it does not stop in time.summary generated by Copilot