Skip to content
Merged
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
8 changes: 8 additions & 0 deletions lib/ruby_lsp/setup_bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ def run_bundle_install(bundle_gemfile = @gemfile)
# If no error occurred, then clear previous errors
@error_path.delete if @error_path.exist?
$stderr.puts("Ruby LSP> Composed bundle installation complete")
rescue Errno::EPIPE
# If the $stderr pipe was closed by the client, for example when closing the editor during running bundle
# install, we don't want to write the error to a file or else we will report to telemetry on the next launch and
# it does not represent an actual error.
#
# This situation may happen because while running bundle install, the server is not yet ready to receive
# shutdown requests and we may continue doing work until the process is killed.
@error_path.delete if @error_path.exist?
rescue => e
# Write the error object to a file so that we can read it from the parent process
@error_path.write(Marshal.dump(e))
Expand Down
22 changes: 22 additions & 0 deletions test/setup_bundler_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,28 @@ def test_ignores_bundle_package
end
end

def test_is_resilient_to_pipe_being_closed_by_client_during_compose
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
File.write(File.join(dir, "gems.rb"), <<~GEMFILE)
source "https://rubygems.org"
gem "irb"
GEMFILE

Bundler.with_unbundled_env do
capture_subprocess_io do
system("bundle install")

compose = RubyLsp::SetupBundler.new(dir, launcher: true)
compose.expects(:run_bundle_install_directly).raises(Errno::EPIPE)
compose.setup!
refute_path_exists(File.join(dir, ".ruby-lsp", "install_error"))
end
end
end
end
end

private

def with_default_external_encoding(encoding, &block)
Expand Down