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

refactor(lsp): remove RwLock on Config #13485

Merged
merged 4 commits into from
Jan 25, 2022

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Jan 25, 2022

  1. Removes the RwLock on Config so the config state is behind the same lsp mutex as mostly everything else
  2. Removes the occurence of calling back to the client while holding onto the LSP mutex's lock (potential deadlocking scenario based on how the client is implemented).

Maybe fixes #13477.

) -> AsyncReturn<Result<Vec<serde_json::Value>, AnyError>>;
uris: Vec<lsp::Url>,
) -> AsyncReturn<Result<Vec<Result<SpecifierSettings, AnyError>>, AnyError>>;
fn workspace_configuration(&self) -> AsyncReturn<Result<Value, AnyError>>;
Copy link
Member Author

Choose a reason for hiding this comment

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

Instead of having a low level configuration method on the Client, I've split it up into two separate higher level functions. This simplifies the caller code and the REPL implementation of this trait.

@@ -236,149 +242,62 @@ pub struct Settings {
#[derive(Debug)]
pub struct Config {
pub client_capabilities: ClientCapabilities,
settings: Arc<RwLock<Settings>>,
tx: mpsc::Sender<ConfigRequest>,
settings: Settings,
Copy link
Member Author

Choose a reason for hiding this comment

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

The RwLock on this is removed along with the separate thread to call the client (it's now just fired off in a task and returns to use the same LanguageServer mutex)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yeah, ok... That whole tx/sender bit was to work around deadlocking issues I remember now, so removing it all together is a big 👍 .

scope_uri: None,
section: Some(SETTINGS_SECTION.to_string()),
}])
.await;
Copy link
Member Author

Choose a reason for hiding this comment

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

Here is the call that could cause a deadlock depending on how the client is implemented. Now this always happens outside the LanguageServer mutex.

@dsherret dsherret marked this pull request as ready for review January 25, 2022 03:36
@dsherret dsherret requested a review from kitsonk as a code owner January 25, 2022 03:36
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... and now I remember the whole "configuration server" stuff was to get around a deadlock issue way back when, so it is good to actually remove the RwLock all together... Thank you!

@@ -236,149 +242,62 @@ pub struct Settings {
#[derive(Debug)]
pub struct Config {
pub client_capabilities: ClientCapabilities,
settings: Arc<RwLock<Settings>>,
tx: mpsc::Sender<ConfigRequest>,
settings: Settings,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yeah, ok... That whole tx/sender bit was to work around deadlocking issues I remember now, so removing it all together is a big 👍 .

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

LGTM too

@dsherret dsherret merged commit d4dd9ae into denoland:main Jan 25, 2022
@dsherret dsherret deleted the config_remove_rw_lock branch January 25, 2022 15:30
bartlomieju pushed a commit that referenced this pull request Jan 27, 2022
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.

lsp: constant 100% cpu usage
3 participants