-
Notifications
You must be signed in to change notification settings - Fork 186
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
Locate targets under mutex lock #2976
Conversation
006f5b1
to
6980656
Compare
6980656
to
b51049e
Compare
@st0012 I made a new attempt at this one and split by commit. I realized that documents needed more than one piece of the global state (encoding + mutex), so we can actually pass the state down without making it too messy. The benefit is that now there's no way to locate targets bypassing the lock, as you had suggested. Let me know what you think! |
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 👍
b51049e
to
a227dd4
Compare
Merge activity
|
### Motivation Closes #3027 The deadlock bug was introduced in #2976. Essentially, if the editor opens a URI for a non-existing file, we try to acquire the same lock twice. Once [here](https://github.com/Shopify/ruby-lsp/blob/17d5fc733b758bbbedaf36fb17ac3914548086bf/lib/ruby_lsp/base_server.rb#L53) to verify if the request requires a document to be parsed and the second time [here](https://github.com/Shopify/ruby-lsp/blob/17d5fc733b758bbbedaf36fb17ac3914548086bf/lib/ruby_lsp/store.rb#L68) when we read the file from disk and save it in the store. Trying to acquire the same mutex lock twice raises the deadlock error. ### Implementation I stopped synchronizing anything inside basic store operations. It just increases the chance of mistakes like these. I moved the responsibility of synchronizing back to the server. ### Automated Tests To catch this regression, we need a client/server integration test because the first synchronization happens only by reading a request from the STDIN pipe. I added one to ensure we don't hit the same issue again.
Motivation
I'm hoping this is the solution for #2446
My hypothesis is that we're seeing a concurrency issue where threads switch in the middle of locating targets and then the document gets mutated. That would render the location we're currently searching for invalid, which can then lead to infinite loops.
Implementation
My idea is to move our mutex into the global state so that we can use it in more places. Then we lock the mutex while locating targets to avoid having any document edits be applied in the middle.
Note: I experimented with passing the mutex down to the document instances, but it was a bit messier.