Skip to content

Conversation

soulomoon
Copy link
Collaborator

@soulomoon soulomoon commented Aug 24, 2025

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.

  • Added a new resExit barrier to LanguageContextState and an isExiting function to track when the server should exit, ensuring that the server stops processing messages after an exit notification is received. [1]
  • Enhanced clientOut to catch and log BrokenPipe errors when sending output fails (e.g., if the client closes the output handle), including a truncated version of the outgoing message for debugging.
  • Replaced manual thread management with withAsync and race to better manage the sender thread lifecycle and ensure clean shutdowns. [1]
  • Updated the sendServer function 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.
  • exitNotificationHandler now do nothing.

summary generated by Copilot

- Catch and report broken pipe (resource vanished) when sending responses;
	log up to 400 chars of the outgoing message for context.
- stop client sender after a shutdown response is sent.
@soulomoon soulomoon changed the title Gracefullyexit Gracefully exit the server Aug 24, 2025
@michaelpj
Copy link
Collaborator

Do you want a review on this yet?

@soulomoon
Copy link
Collaborator Author

Yes, the this MR is ready for review, but the corresponding hls changes at haskell/haskell-language-server#4701 still need some more polishing.

@soulomoon soulomoon marked this pull request as ready for review August 26, 2025 13:32
soulomoon and others added 3 commits August 26, 2025 21:33
if startDelay and updateDelay are 0. It ensures
that test cases relying on progress notifications
to be sent are not flaky.
@soulomoon soulomoon marked this pull request as draft August 28, 2025 18:07
@soulomoon
Copy link
Collaborator Author

soulomoon commented Aug 28, 2025

I am parking the progress notification fix here so I can test the flakiness in hls in one go. Turn it back to draft again.

@soulomoon soulomoon marked this pull request as ready for review August 28, 2025 18:42
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

Successfully merging this pull request may close these issues.

2 participants