Skip to content
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

fix(lsp): fix deadlocks, use one big mutex #9271

Merged
merged 1 commit into from
Jan 26, 2021

Conversation

bnoordhuis
Copy link
Contributor

The LSP code had numerous places where competing threads could take out
out locks in different orders, making it very prone to deadlocks.
This commit sidesteps the entire issue by switching to a single lock.

The above is a little white lie: the Sources struct still uses a mutex
internally to avoid having to boil the ocean (because being honest about
what it does involves changing all its methods to &mut self but that
ripples out extensively...) I'll save that one for another day.

@kitsonk
Copy link
Contributor

kitsonk commented Jan 25, 2021

Very cool, thank you. I did a quick glance and it looks good to me, but I am going to take this branch for a spin and see if I can break it. I suspect I won't be able to.

Copy link
Contributor

@kitsonk kitsonk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I tried fairly hard to break it. A debug build feels a bit "laggy" but it can be that way with a debug build without this, while a release build was as snappy as can be. At the very least this gives us a place to iterate from and it is a lot cleaner.

The LSP code had numerous places where competing threads could take out
out locks in different orders, making it very prone to deadlocks.
This commit sidesteps the entire issue by switching to a single lock.

The above is a little white lie: the Sources struct still uses a mutex
internally to avoid having to boil the ocean (because being honest about
what it does involves changing all its methods to `&mut self` but that
ripples out extensively...) I'll save that one for another day.
@bnoordhuis bnoordhuis merged commit 2828690 into denoland:master Jan 26, 2021
@bnoordhuis bnoordhuis deleted the lsp-demutox branch January 26, 2021 09:55
bnoordhuis added a commit to bnoordhuis/deno that referenced this pull request Feb 5, 2021
The mutex was used to hide the fact that the Sources object mutates
itself when it's queried. Be honest about that and mark everything that
directly or indirectly mutates it as `mut`.

This is a follow-up to commit 2828690
from last month ("fix(lsp): fix deadlocks, use one big mutex (denoland#9271)")
bnoordhuis added a commit to bnoordhuis/deno that referenced this pull request Feb 6, 2021
The mutex was used to hide the fact that the Sources object mutates
itself when it's queried. Be honest about that and mark everything that
directly or indirectly mutates it as `mut`.

This is a follow-up to commit 2828690
from last month ("fix(lsp): fix deadlocks, use one big mutex (denoland#9271)")
bnoordhuis added a commit that referenced this pull request Feb 8, 2021
The mutex was used to hide the fact that the Sources object mutates
itself when it's queried. Be honest about that and mark everything that
directly or indirectly mutates it as `mut`.

This is a follow-up to commit 2828690
from last month ("fix(lsp): fix deadlocks, use one big mutex (#9271)")
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.

None yet

2 participants