From 50ad82b4260be69a9173b356947492e05b003792 Mon Sep 17 00:00:00 2001 From: Shubhangi singh Date: Tue, 8 Oct 2024 11:30:03 +0000 Subject: [PATCH 1/2] feat(core): add ECONNRESET errors as retriable error --- google-apis-core/lib/google/apis/core/http_command.rb | 7 ++++++- .../spec/google/apis/core/http_command_spec.rb | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/google-apis-core/lib/google/apis/core/http_command.rb b/google-apis-core/lib/google/apis/core/http_command.rb index 70ce4249fe5..ab2a0b5087d 100644 --- a/google-apis-core/lib/google/apis/core/http_command.rb +++ b/google-apis-core/lib/google/apis/core/http_command.rb @@ -292,7 +292,12 @@ def error(err, rethrow: false, &block) rescue Google::Apis::Error => e err = e end - elsif err.is_a?(HTTPClient::TimeoutError) || err.is_a?(SocketError) || err.is_a?(HTTPClient::KeepAliveDisconnected) || err.is_a?(Errno::ECONNREFUSED) || err.is_a?(Errno::ETIMEDOUT) + elsif err.is_a?(HTTPClient::TimeoutError) || + err.is_a?(SocketError) || + err.is_a?(HTTPClient::KeepAliveDisconnected) || + err.is_a?(Errno::ECONNREFUSED) || + err.is_a?(Errno::ETIMEDOUT) || + err.is_a?(Errno::ECONNRESET) err = Google::Apis::TransmissionError.new(err) end block.call(nil, err) if block_given? diff --git a/google-apis-core/spec/google/apis/core/http_command_spec.rb b/google-apis-core/spec/google/apis/core/http_command_spec.rb index 55ddaf4652a..c10421e09b7 100644 --- a/google-apis-core/spec/google/apis/core/http_command_spec.rb +++ b/google-apis-core/spec/google/apis/core/http_command_spec.rb @@ -495,6 +495,13 @@ class SecretPayload expect { command.execute(client) }.to raise_error(Google::Apis::TransmissionError) end + it 'should raise transmission error for broken network connection' do + stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_raise(Errno::ETIMEDOUT) + command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals') + command.options.retries = 0 + expect { command.execute(client) }.to raise_error(Google::Apis::TransmissionError) + end + it 'should raise rate limit error for 429 status codes' do stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_return(status: [429, '']) command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals') From c30e56689268d05fa2e9a9cc1fee918a40adef9d Mon Sep 17 00:00:00 2001 From: Shubhangi Singh Date: Thu, 10 Oct 2024 04:07:21 +0000 Subject: [PATCH 2/2] fixing test case --- google-apis-core/spec/google/apis/core/http_command_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/google-apis-core/spec/google/apis/core/http_command_spec.rb b/google-apis-core/spec/google/apis/core/http_command_spec.rb index c10421e09b7..7d865e2f4e9 100644 --- a/google-apis-core/spec/google/apis/core/http_command_spec.rb +++ b/google-apis-core/spec/google/apis/core/http_command_spec.rb @@ -496,7 +496,7 @@ class SecretPayload end it 'should raise transmission error for broken network connection' do - stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_raise(Errno::ETIMEDOUT) + stub_request(:get, 'https://www.googleapis.com/zoo/animals').to_raise(Errno::ECONNRESET) command = Google::Apis::Core::HttpCommand.new(:get, 'https://www.googleapis.com/zoo/animals') command.options.retries = 0 expect { command.execute(client) }.to raise_error(Google::Apis::TransmissionError)