Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 528
Pavan Avatar asked Mar 30 '18 02:03

Pavan


People also ask

What does connection reset by peer error mean?

This error is generated when the OS receives notification of TCP Reset (RST) from the remote peer. Connection reset by peer means the TCP stream was abnormally closed from the other end. A TCP RST was received and the connection is now closed.

What is TCP reset by peer?

This error is generated when the OS receives notification of TCP Reset (RST) from the remote peer. Connection reset by peer means the TCP stream was abnormally closed from the other end.

What happens when I send the RST bit to a peer?

The peer will return the data packet you sent while sending the RST (reset) bit and forcefully terminate the connection. This issue usually happens if you are being blocked by the Firewall on any point in the route.

What is the difference between RST and connection reset by peer?

“Connection reset by peer” is the TCP/IP equivalent of slamming the phone back on the hook. It’s more polite than merely not replying, leaving one hanging. But it’s not the FIN-ACK expected of the truly polite TCP/IP. RST is used to abort connections.


1 Answers

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
like image 188
fool-dev Avatar answered Sep 23 '22 17:09

fool-dev