From fb4bc1d5a9abf2c353059872040ad0e6bff9fa3d Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 17 Apr 2024 09:40:09 +0100 Subject: [PATCH] (bug) - Add synchronization to Dir.chdir in init_puppet_lint This commit wraps the `Dir.chdir` call in the `validation_provider.rb` file within a `$PuppetParserMutex.synchronize` block. Before this change, the `Dir.chdir` method was called without synchronization, which could lead to conflicts if another `chdir` block was in progress. This change prevents the error "(puppet/fixDiagnosticErrors) conflicting chdir during another chdir block" by ensuring that the `Dir.chdir` call is only executed by one thread at a time. --- lib/puppet-languageserver/manifest/validation_provider.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/puppet-languageserver/manifest/validation_provider.rb b/lib/puppet-languageserver/manifest/validation_provider.rb index 2daa3298..7034ef56 100644 --- a/lib/puppet-languageserver/manifest/validation_provider.rb +++ b/lib/puppet-languageserver/manifest/validation_provider.rb @@ -109,7 +109,9 @@ def self.init_puppet_lint(root_dir, lint_options = []) linter_options = PuppetLint::OptParser.build else begin - Dir.chdir(root_dir.to_s) { linter_options = PuppetLint::OptParser.build } + $PuppetParserMutex.synchronize do # rubocop:disable Style/GlobalVars + Dir.chdir(root_dir.to_s) { linter_options = PuppetLint::OptParser.build } + end rescue OptionParser::InvalidOption => e PuppetLanguageServer.log_message(:error, "(#{name}) Error reading Puppet Lint configuration. Using default: #{e}") linter_options = PuppetLint::OptParser.build