Errno::ECONNRESET:使用 rest-client 在 Rails 中由对等方重置连接 [英] Errno::ECONNRESET: Connection reset by peer in Rails using rest-client
问题描述
我们有一个 Ruby on Rails 应用程序,它具有搜索"功能(搜索某个公司).从浏览器用户输入一些名称并点击搜索,这个搜索对外部系统进行一个休息 api 调用,并为我们提供一些搜索结果.
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.
我们正在使用rest-client"(用于 Ruby on Rails).
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: 连接被 peer 重置
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.
问题:
- 可能导致此重置问题"的原因
- 为什么在我的 prod 乘客重置后它又开始工作了.
- 我们使用reset-client应该会写一段代码在这个异常发生时手动关闭连接.
- 防火墙是否有任何问题可能导致这种情况?
- 是否可以在异常中放置任何代码来重新启动此连接,以便下次调用成功.
代码:
def call
resp_data = RestClient.get(@request_url, @header)
rescue => error
puts 'Exception: ' error.message
end
推荐答案
试试下面的
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
这篇关于Errno::ECONNRESET:使用 rest-client 在 Rails 中由对等方重置连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!