From eee97ad29a818bfb1469cdea14a6fa5ad78b69f8 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Tue, 24 Jan 2023 11:07:29 +0000 Subject: [PATCH] DEV: Patch capybara to ignore client-triggered errors (#19972) In dev/prod, these are absorbed by unicorn. Most commonly, they occur when a client interrupts a message-bus long-polling request. Also reverts the EPIPE workaround introduced in 011c9b997331a0c5a88a5d498bfcc0d8b06cf22d --- config/initializers/004-message_bus.rb | 2 -- spec/rails_helper.rb | 11 +++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config/initializers/004-message_bus.rb b/config/initializers/004-message_bus.rb index e6f1b19c6b9..383d8a01134 100644 --- a/config/initializers/004-message_bus.rb +++ b/config/initializers/004-message_bus.rb @@ -105,8 +105,6 @@ MessageBus.on_middleware_error do |env, e| [403, {}, ["Invalid Access"]] elsif RateLimiter::LimitExceeded === e [429, { "Retry-After" => e.available_in.to_s }, [e.description]] - elsif Errno::EPIPE === e - [422, {}, ["Closed by Client"]] end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 02aa2e80cdc..22009af6faa 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -252,6 +252,17 @@ RSpec.configure do |config| capybara_config.server_port = 31_337 + ENV["TEST_ENV_NUMBER"].to_i end + module IgnoreUnicornCapturedErrors + def raise_server_error! + super + rescue EOFError, Errno::ECONNRESET, Errno::EPIPE, Errno::ENOTCONN => e + # Ignore these exceptions - caused by client. Handled by unicorn in dev/prod + # https://github.com/defunkt/unicorn/blob/d947cb91cf/lib/unicorn/http_server.rb#L570-L573 + end + end + + Capybara::Session.class_eval { prepend IgnoreUnicornCapturedErrors } + # The valid values for SELENIUM_BROWSER_LOG_LEVEL are: # # OFF