lib/sqewer/connection.rb in sqewer-8.0.0 vs lib/sqewer/connection.rb in sqewer-8.0.1

- old
+ new

@@ -74,10 +74,18 @@ wait_time_seconds: DEFAULT_TIMEOUT_SECONDS, max_number_of_messages: BATCH_RECEIVE_SIZE ) response.messages.map {|message| Message.new(message.receipt_handle, message.body, message.attributes) } end + rescue Aws::Errors::MissingCredentialsError + # We noticed cases where errors related to AWS credentials started to happen suddenly. + # We don't know the root cause yet, but what we can do is release the + # singleton @client instance because it contains a cache of credentials that in most + # cases is no longer valid. + self.class.release_client + + raise end # Send a message to the backing queue # # @param message_body[String] the message to send @@ -200,10 +208,16 @@ yield(buffer) buffer.each_batch {|batch| handle_batch_with_retries(:delete_message_batch, batch) } end + protected + + def self.release_client + @client = nil + end + private def network_and_aws_sdk_errors [NotOurFaultAwsError, Seahorse::Client::NetworkingError, Aws::SQS::Errors::InternalError] end @@ -219,7 +233,15 @@ # We set the 'batch' param to an array with only the failed messages so only those get retried batch = aws_failures.map {|aws_response_message| batch.find { |m| aws_response_message.id.to_s == m[:id] }} raise NotOurFaultAwsError end end + rescue Aws::Errors::MissingCredentialsError + # We noticed cases where errors related to AWS credentials started to happen suddenly. + # We don't know the root cause yet, but what we can do is release the + # singleton @client instance because it contains a cache of credentials that in most + # cases is no longer valid. + self.class.release_client + + raise end end