SSL_connect (Errno::ECONNRESET)

Posted

技术标签:

【中文标题】SSL_connect (Errno::ECONNRESET)【英文标题】: 【发布时间】:2016-06-08 11:41:38 【问题描述】:

我们有基于黄瓜的 UI 自动化测试框架。最近我们从 Ruby 1.9.x 迁移到 2.2.0,之后我们在通过测试框架登录到我们的应用程序时遇到了问题。它说 SSL 连接重置问题。

错误跟踪:

07:01:26 An existing connection was forcibly closed by the remote host. - 
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/httpclient-2.7.1/lib/httpclient/ssl_socket.rb:46:in `connect'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/httpclient-2.7.1/lib/httpclient/ssl_socket.rb:46:in `ssl_connect'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/httpclient-2.7.1/lib/httpclient/ssl_socket.rb:24:in `create_socket'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/httpclient-2.7.1/lib/httpclient/session.rb:739:in `block in connect'
07:01:26 D:/Ruby223/lib/ruby/2.2.0/timeout.rb:88:in `block in timeout'
07:01:26 D:/Ruby223/lib/ruby/2.2.0/timeout.rb:98:in `call'
07:01:26 D:/Ruby223/lib/ruby/2.2.0/timeout.rb:98:in `timeout'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/httpclient-2.7.1/lib/httpclient/session.rb:735:in `connect'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/httpclient-2.7.1/lib/httpclient/session.rb:497:in `query'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/httpclient-2.7.1/lib/httpclient/session.rb:170:in `query'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/httpclient-2.7.1/lib/httpclient.rb:1238:in `do_get_block'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/httpclient-2.7.1/lib/httpclient.rb:1021:in `block in do_request'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/httpclient-2.7.1/lib/httpclient.rb:1129:in `protect_keep_alive_disconnected'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/httpclient-2.7.1/lib/httpclient.rb:1016:in `do_request'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/httpclient-2.7.1/lib/httpclient.rb:858:in `request'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/httpclient-2.7.1/lib/httpclient.rb:761:in `post'
<-- our Code for login kick in to call httpclient --->
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/cucumber-2.3.2/lib/cucumber/rb_support/rb_language.rb:96:in `load'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/cucumber-2.3.2/lib/cucumber/rb_support/rb_language.rb:96:in `load_code_file'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/cucumber-2.3.2/lib/cucumber/runtime/support_code.rb:142:in `load_file'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/cucumber-2.3.2/lib/cucumber/runtime/support_code.rb:84:in `block in load_files!'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/cucumber-2.3.2/lib/cucumber/runtime/support_code.rb:83:in `each'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/cucumber-2.3.2/lib/cucumber/runtime/support_code.rb:83:in `load_files!'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/cucumber-2.3.2/lib/cucumber/runtime.rb:254:in `load_step_definitions'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/cucumber-2.3.2/lib/cucumber/runtime.rb:62:in `run!'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/cucumber-2.3.2/lib/cucumber/cli/main.rb:32:in `execute!'
07:01:26 D:/Ruby223/lib/ruby/gems/2.2.0/gems/cucumber-2.3.2/bin/cucumber:8:in `<top (required)>'

【问题讨论】:

你解决了吗?有同样的问题......我有一个使用 Ruby 1.9.3 和 rest-client 的测试套件也有同样的问题。我们正在 IIS 上针对 C# webapp 运行。 【参考方案1】:

在迁移到 ruby​​ 2.0.0 后不久我遇到了同样的问题

按照以下步骤解决

1)访问urlhttp://curl.haxx.se/ca/cacert.pem 将内容保存为.pem文件(不要保存为文本文件。确保扩展名是.pem)

2)将文件复制到本地的任何路径,例如:C:\ruby200\ca_cert.pem(在我的情况下)

3) 现在添加一个带有变量 SSL_CERT_FILE 和值“C:\ruby200\ca_cert.pem”(不带引号)的环境变量(路径在我的情况下。替换为适当的路径) (可以通过导航到计算机 -> 高级设置 -> 环境变量来添加环境变量)

4)关闭所有命令提示符并重新启动它们。现在应该可以正常工作了

【讨论】:

【参考方案2】:

我认为您的 gem 已更新。在您的代码中添加这些行以解决问题

http.verify_mode = OpenSSL::SSL::VERIFY_NONE

http.use_ssl = true之前

我希望这可以解决问题。

【讨论】:

禁用 ssl 验证是一个非常糟糕的主意。你不应该在生产系统中使用它。 我可以在内部测试 webapp。几乎。我更喜欢使用证书验证对等方。

以上是关于SSL_connect (Errno::ECONNRESET)的主要内容,如果未能解决你的问题,请参考以下文章

C中重复的SSL_connect导致SIGSEGV

SSL_connect: SSL_ERROR_SYSCALL 连接到 github.com:443

Ubuntu 20.04 出现 SSL_connect: error:1425F102 .. unsupported protocol问题的解决

SSL_connect 返回=1 errno=0 state=SSLv3 读取服务器证书B:证书验证失败

检索 PEM 证书:SSL_connect 返回=1 errno=0 状态=SSLv3 读取服务器证书 B:证书验证失败

OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443