Fix Drop for Server deadlock behavior
#75
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes two possible deadlocks that cause
elp serverto hang during exit. I was on the right track in #74 but there are actually two deadlocks:Senderof theConnection(because theLspLoggerclones it one). This can cause a deadlock when a message is not logged following the drop ofServeronio_threads.join()because theConnection's thread for receiving messages from theConnection'sReceiverawaits messages indefinitely. The solution for this deadlock is to remove theLspLoggerfrom the backend onDropof the server (or any time earlier). That decrements the reference count on theSenderand causes theReceiver's iterator to returnNoneresulting in the termination of its thread.Drop for Serverhangs 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