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

LS: Fix hangs while spawning diagnostics tasks #6679

Open
wants to merge 1 commit into
base: spr/main/2a95e833
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ impl DiagnosticsControllerThread {

/// Shortcut for spawning a worker task which does the boilerplate around cloning state parts
/// and catching panics.
// FIXME(mkaput): Spawning tasks seems to hang on initial loads, this is probably due to
// task queue being overloaded.
fn spawn_worker(&self, f: impl FnOnce(ProjectDiagnostics, Notifier) + Send + 'static) {
let project_diagnostics = self.project_diagnostics.clone();
let notifier = self.notifier.clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
//! The thread pool is implemented entirely using
//! the threading utilities in [`crate::server::schedule::thread`].

use std::cmp::min;
use std::num::NonZero;
use std::thread::available_parallelism;

use crossbeam::channel::{Receiver, Sender, bounded};
use crossbeam::channel;

use super::{Builder, JoinHandle, ThreadPriority};

Expand All @@ -38,7 +37,7 @@ pub struct Pool {
// make sure to keep `job_sender` above `handles`
// so that the channel is actually closed
// before we join the worker threads!
job_sender: Sender<Job>,
job_sender: channel::Sender<Job>,
_handles: Vec<JoinHandle>,

parallelism: NonZero<usize>,
Expand Down Expand Up @@ -67,16 +66,15 @@ impl Pool {

let threads = available_parallelism().map(usize::from).unwrap_or(DEFAULT_PARALLELISM);

// Channel buffer capacity is between 2 and 4, depending on the pool size.
let (job_sender, job_receiver) = bounded(min(threads * 2, DEFAULT_PARALLELISM));
let (job_sender, job_receiver) = channel::unbounded();

let mut handles = Vec::with_capacity(threads);
for i in 0..threads {
let handle = Builder::new(INITIAL_PRIORITY)
.stack_size(STACK_SIZE)
.name(format!("cairo-ls:worker:{i}"))
.spawn({
let job_receiver: Receiver<Job> = job_receiver.clone();
let job_receiver: channel::Receiver<Job> = job_receiver.clone();
move || {
let mut current_priority = INITIAL_PRIORITY;
for job in job_receiver {
Expand Down