Skip to content

Conversation

@the-mikedavis
Copy link
Contributor

@the-mikedavis the-mikedavis commented Jan 30, 2025

This fixes two possible deadlocks that cause elp server to hang during exit. I was on the right track in #74 but there are actually two deadlocks:

  • The first happens because the logger backend has a clone of the Sender of the Connection (because the LspLogger clones it one). This can cause a deadlock when a message is not logged following the drop of Server on io_threads.join() because the Connection's thread for receiving messages from the Connection's Receiver awaits messages indefinitely. The solution for this deadlock is to remove the LspLogger from the backend on Drop of the server (or any time earlier). That decrements the reference count on the Sender and causes the Receiver's iterator to return None resulting in the termination of its thread.
  • The second I don't really understand fully. The Drop for Server hangs because the cache task pool's drop joins its threads (by design) and there is an outstanding task that seems to be frozen, I think related to Salsa's cancellation mechanism. Explicitly requesting cancellation during drop eliminates this problem. Plus it matches what rust-analyzer does.

Fixes #36

This fixes two possible deadlocks that cause `elp server` to hang during
exit.

* The first happens because the logger backend has a clone of the
  `Sender` of the `Connection`. This can cause a deadlock when a message
  is _not_ logged following the drop of `Server` on `io_threads.join()`
  because the `Connection`'s thread for receiving message's from the
  `Connection`'s `Receiver` awaits messages indefinitely. The solution
  for this deadlock is to remove the `LspLogger` from the backend on
  `Drop` of the server (or any time earlier). That decrements the
  reference count on the `Sender` and causes the `Receiver`'s iterator
  to return `None` resulting in the termination of its thread.
* The second I don't really understand fully. The `Drop for Server`
  hangs because the cache task pool's drop joins its threads (by design)
  and there is an outstanding task that seems to be frozen, I think
  related to Salsa's cancellation mechanism. Explicitly requesting
  cancellation during drop eliminates this problem.
@facebook-github-bot
Copy link
Contributor

@alanz has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@alanz merged this pull request in 9e55192.

@the-mikedavis the-mikedavis deleted the md/exit-deadlock branch February 5, 2025 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

elp server process stays up after a window reload

2 participants