Skip to content

Commit 55d41b1

Browse files
authored
Avoid writing error file if client is closed during bundle compose (#3649)
1 parent 0d3b50c commit 55d41b1

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/ruby_lsp/setup_bundler.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@ def run_bundle_install(bundle_gemfile = @gemfile)
234234
# If no error occurred, then clear previous errors
235235
@error_path.delete if @error_path.exist?
236236
$stderr.puts("Ruby LSP> Composed bundle installation complete")
237+
rescue Errno::EPIPE
238+
# If the $stderr pipe was closed by the client, for example when closing the editor during running bundle
239+
# install, we don't want to write the error to a file or else we will report to telemetry on the next launch and
240+
# it does not represent an actual error.
241+
#
242+
# This situation may happen because while running bundle install, the server is not yet ready to receive
243+
# shutdown requests and we may continue doing work until the process is killed.
244+
@error_path.delete if @error_path.exist?
237245
rescue => e
238246
# Write the error object to a file so that we can read it from the parent process
239247
@error_path.write(Marshal.dump(e))

test/setup_bundler_test.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,28 @@ def test_ignores_bundle_package
914914
end
915915
end
916916

917+
def test_is_resilient_to_pipe_being_closed_by_client_during_compose
918+
Dir.mktmpdir do |dir|
919+
Dir.chdir(dir) do
920+
File.write(File.join(dir, "gems.rb"), <<~GEMFILE)
921+
source "https://rubygems.org"
922+
gem "irb"
923+
GEMFILE
924+
925+
Bundler.with_unbundled_env do
926+
capture_subprocess_io do
927+
system("bundle install")
928+
929+
compose = RubyLsp::SetupBundler.new(dir, launcher: true)
930+
compose.expects(:run_bundle_install_directly).raises(Errno::EPIPE)
931+
compose.setup!
932+
refute_path_exists(File.join(dir, ".ruby-lsp", "install_error"))
933+
end
934+
end
935+
end
936+
end
937+
end
938+
917939
private
918940

919941
def with_default_external_encoding(encoding, &block)

0 commit comments

Comments
 (0)