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): avoid calling client while holding lock #18197

Merged
merged 16 commits into from
Mar 15, 2023

Conversation

dsherret
Copy link
Member

@dsherret dsherret commented Mar 14, 2023

Extracted and improved out of #17979

I think this gets all the remaining parts of the code that call into the client awaiting while holding onto the lsp lock.

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, but I have a question about how tasks are spawned

Comment on lines +46 to +49
/// Gets additional methods that should only be called outside
/// the LSP's lock to prevent deadlocking scenarios.
pub fn when_outside_lsp_lock(&self) -> OutsideLockClient {
OutsideLockClient(self.0.clone())
Copy link
Member

Choose a reason for hiding this comment

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

Great idea 👍

self.0.send_registry_state_notification(params).await;
// do on a task in case the caller currently is in the lsp lock
let client = self.0.clone();
tokio::task::spawn(async move {
Copy link
Member

Choose a reason for hiding this comment

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

Does it need to be spawn instead of spawn_local? I.e does it need to run on a separate thread?

Copy link
Member Author

Choose a reason for hiding this comment

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

Doesn't work:

thread '<unnamed>' panicked at '`spawn_local` called from outside of a `task::LocalSet`', cli\lsp\client.rs:66:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[Info  - 9:57:12 AM] Connection to server got closed. Server will restart.

Copy link
Member

Choose a reason for hiding this comment

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

Interesting! I guess this all circles back to issue in 18079

cli/lsp/client.rs Show resolved Hide resolved
cli/lsp/client.rs Show resolved Hide resolved
@dsherret dsherret enabled auto-merge (squash) March 15, 2023 14:19
@dsherret dsherret merged commit 7070b8e into denoland:main Mar 15, 2023
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