如何解决Rack Lint错误?

yll*_*ate 5 ruby rack ruby-on-rails unicorn ruby-on-rails-3

我注意到某些请求,特别是来自Uptime Robot的测试页面正常运行时间最近开始在我的Rails 3.1.x应用程序上生成了以下Rack Lint错误:

21:47:05 web.1     | Started HEAD "/" for 74.86.158.106 at 2012-03-22 21:47:05 -0400
21:47:05 web.1     |   Processing by HomeController#index as */*
...
21:47:05 web.1     | /Users/username/.rvm/gems/ruby-1.9.3-p125@project/gems/activesupport-3.1.4/lib/active_support/core_ext/string/output_safety.rb:23: warning: regexp match /.../n against to UTF-8 string
...
21:47:05 web.1     | Completed 200 OK in 81ms (Views: 60.3ms | ActiveRecord: 0.0ms)
21:47:05 web.1     | 74.86.158.106 - - [22/Mar/2012 21:47:05] "GET / HTTP/1.1" 200 31842 0.1993
21:47:05 web.1     | E, [2012-03-22T21:47:05.546848 #18938] ERROR -- : app error: Content-Length header was 31842, but should be 0 (Rack::Lint::LintError)
21:47:05 web.1     | E, [2012-03-22T21:47:05.546978 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125@project/gems/rack-1.3.6/lib/rack/lint.rb:19:in `assert'
21:47:05 web.1     | E, [2012-03-22T21:47:05.547079 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125@project/gems/rack-1.3.6/lib/rack/lint.rb:501:in `verify_content_length'
21:47:05 web.1     | E, [2012-03-22T21:47:05.547178 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125@project/gems/rack-1.3.6/lib/rack/lint.rb:525:in `each'
21:47:05 web.1     | E, [2012-03-22T21:47:05.547277 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125@project/gems/rack-1.3.6/lib/rack/body_proxy.rb:23:in `method_missing'
21:47:05 web.1     | E, [2012-03-22T21:47:05.547375 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125@project/gems/unicorn-4.2.0/lib/unicorn/http_response.rb:41:in `http_response_write'
21:47:05 web.1     | E, [2012-03-22T21:47:05.547476 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125@project/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:538:in `process_client'
21:47:05 web.1     | E, [2012-03-22T21:47:05.547574 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125@project/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:604:in `worker_loop'
21:47:05 web.1     | E, [2012-03-22T21:47:05.547672 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125@project/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:487:in `spawn_missing_workers'
21:47:05 web.1     | E, [2012-03-22T21:47:05.547770 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125@project/gems/unicorn-4.2.0/lib/unicorn/http_server.rb:137:in `start'
21:47:05 web.1     | E, [2012-03-22T21:47:05.547867 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125@project/gems/unicorn-4.2.0/bin/unicorn:121:in `<top (required)>'
21:47:05 web.1     | E, [2012-03-22T21:47:05.547966 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125@project/bin/unicorn:19:in `load'
21:47:05 web.1     | E, [2012-03-22T21:47:05.548063 #18938] ERROR -- : /Users/username/.rvm/gems/ruby-1.9.3-p125@project/bin/unicorn:19:in `<main>'
Run Code Online (Sandbox Code Playgroud)

关于这里可能会发生什么的任何想法?我现在真的没有找到一个解决方案,专门解决在这个场景中应该做什么,以及寻找和追捕真正可能发生的事情.

Las*_*ert 1

我知道这是一个老问题,但我有完全相同的问题。来自 UptimeRobot 和 New Relic 的请求(并且仅来自这两个的 IP)会提供这些日志消息。

UptimeRobot 和 NewRelic 均报告“正常”。

看来Rack::Lint抱怨的不是请求,而是响应。查看堆栈跟踪。它来自http_response_write独角兽(我也使用独角兽)。

我将进行更多调查并在此处添加任何发现。

更新:

我能够重现该问题

$ curl https://example.com -X HEAD -i
HTTP/1.1 200 OK
Server: nginx/1.6.2 (Ubuntu)
Date: Wed, 18 Nov 2015 09:17:11 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 18422
Connection: keep-alive
Status: 200 OK
...

curl: (18) transfer closed with 18422 bytes remaining to read
Run Code Online (Sandbox Code Playgroud)

所以看来我的旧 Rails 不能正确支持 HEAD 请求。

更新:我无法在我的流浪盒或登台服务器上重现。我能想到的与生产环境的唯一区别是 SSL。