Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.7k views
in Technique[技术] by (71.8m points)

ruby - Errno::ECONNRESET: Connection reset by peer in Rails using rest-client

We have a Ruby on Rails application and this has a "search" functionality (search for some company). From browser user key-in some name and hit search and this search make an rest api call to outside system and get us some search results.

We are using "rest-client" (for Ruby on Rails).

I noticed this seems to work for few hours and suddenly my search seems to be broken all of a sudden and I can see in my log I get:

Errno::ECONNRESET: Connection reset by peer

We tried to investigate this issue by looking in to logs and we dont see any logs.

If we need to make this search work again we need to restart the passenger and then it works immediately. This is happening only in production environment. I tested in staging it seems to work well.

Questions:

  1. What could be causing this "reset issue"
  2. Why on my prod passenger reset it starts to work again.
  3. We use reset-client should be write a code to manually close connection when this exception happens.
  4. Any issue in firewall could causing this?
  5. Is there any code I can place in the exception to restart this connection so the next call is success.

Code:

def call
   resp_data = RestClient.get(@request_url, @header)
   rescue => error
     puts 'Exception: ' error.message
end
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try to the following

resp_data = RestClient::Request.new(
    method: :get,
    url: @request_url, #=> https://api.example.com/auth2/endpoint
    :headers => {
        :Authorization => @header, #=> "Bearer access_token",
    }
)

rescue => error
    puts 'Exception: ' error.message

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...