solargraph
solargraph copied to clipboard
Race condition in LSP
I'm seeing this from time to time in spec runs - suspect we need a mutex around chdir blocks:
1) Protocol can format file without file extension
Failure/Error: expect(response['error']).to be_nil
expected: nil
got: {"code"=>-32603, "message"=>"[RuntimeError] conflicting chdir during another chdir block"}
# ./spec/language_server/protocol_spec.rb:472:in `block (2 levels) in <top (required)>'
This was spit out during a recent run of the specs:
#<Thread:0x0000000108c242b0 /Users/broz/src/solargraph/lib/solargraph/language_server/host/diagnoser.rb:45 run> terminated with exception (report_on_exception is true):
/Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/config_loader.rb:80:in `chdir': conflicting chdir during another chdir block (RuntimeError)
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/config_loader.rb:80:in `load_yaml_configuration'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/config_loader.rb:56:in `load_file'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/config_loader_resolver.rb:240:in `block in base_configs'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/config_loader_resolver.rb:239:in `map'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/config_loader_resolver.rb:239:in `base_configs'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/config_loader_resolver.rb:40:in `resolve_inheritance'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/config_loader.rb:67:in `load_file'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/config_loader.rb:122:in `configuration_from_file'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/config_store.rb:68:in `for_dir'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/config_store.rb:58:in `for'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/target_finder.rb:141:in `block in without_excluded'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/target_finder.rb:136:in `reject'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/target_finder.rb:136:in `without_excluded'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/target_finder.rb:132:in `process_explicit_path'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/target_finder.rb:26:in `block in find'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/target_finder.rb:22:in `each'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/target_finder.rb:22:in `find'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/runner.rb:111:in `find_target_files'
from /Users/broz/.rbenv/versions/3.1.6/lib/ruby/gems/3.1.0/gems/rubocop-1.74.0/lib/rubocop/runner.rb:68:in `run'
from /Users/broz/src/solargraph/lib/solargraph/diagnostics/rubocop.rb:31:in `block in diagnose'
from /Users/broz/src/solargraph/lib/solargraph/diagnostics/rubocop_helpers.rb:60:in `redirect_stdout'
from /Users/broz/src/solargraph/lib/solargraph/diagnostics/rubocop.rb:31:in `diagnose'
from /Users/broz/src/solargraph/lib/solargraph/library.rb:392:in `block in diagnose'
from /Users/broz/src/solargraph/lib/solargraph/library.rb:391:in `each_pair'
from /Users/broz/src/solargraph/lib/solargraph/library.rb:391:in `diagnose'
from /Users/broz/src/solargraph/lib/solargraph/language_server/host.rb:216:in `diagnose'
from /Users/broz/src/solargraph/lib/solargraph/language_server/host/diagnoser.rb:66:in `tick'
from /Users/broz/src/solargraph/lib/solargraph/language_server/host/diagnoser.rb:47:in `block in start'
It would probably be better if Solargraph didn't use chdir at all, are there a lot of chdir calls?
Edit: ah I see it's in Rubocop. Maybe worth opening an issue there for it.
Should be fixed by https://github.com/castwide/solargraph/pull/1007, which adds a lock around known directory changes