神秘的轨道错误几乎没有痕迹

神秘的轨道错误几乎没有痕迹

本文介绍了神秘的轨道错误几乎没有痕迹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们遇到一个奇怪的问题,一个爬虫。偶尔会有一些请求会引发 Rails FATAL 错误,但跟踪非常有限,看起来像这样

  [2014-07-01 18:16:37] FATAL Rails:
ArgumentError(invalid%-encoding(c ^ FK + 9u $ _ t Kl
ΥE! = k \̕*ߚ> c +< Oیoʘ> CR!2 D(5 xq#!4 p | 8 IE
:+ H ^ 9` ^ b
= [z)):
lib / locale_middleware.rb:14:在`call'

搜寻器用户代理是



Mozilla / 5.0(兼容; EasouSpider; + http://www.easou。 com / search / spider.html)



我们可以要求它停止通过 robots.txt ,但是如果可能的话,最好是处理根本原因而不是失败500。



我们不能真正重现这个所以有关如何生成类似请求的任何建议都将是非常有帮助的。



我们使用Rails 3.2.19,Unicorn在Ubuntu 12.04上。这是我们的

解决方案

特别感谢Benjamin Sinclaire指出。



解决方案描述了:




  • 安装宝石

  • 将此添加到 application.rb



  config.middleware.use :: Rack :: Robustness do | g | 
g.no_catch_all
g.on(ArgumentError){| ex | 400}
g.content_type'text / plain'
g.body {| ex | ex.message}
g.ensure(true){| ex | env ['rack.errors']。write(ex.message)}
end


We're having a strange problem with one crawler. Occasionally it will throw a Rails FATAL error on some request, but the trace is very limited and looks something like this

[2014-07-01 18:16:37] FATAL Rails :
ArgumentError (invalid %-encoding (c ^   FK+ 9u$_    t  Kl
ΥE!   =k \  ̕* ߚ>c+<O   یo ʘ> C     R! 2 D  (5      x q#!` 4 p      |8 I   E
:+   H^9`^ #    Vo{   >

  =[z     )):
  lib/locale_middleware.rb:14:in `call'

The crawler user-agent is

Mozilla/5.0 (compatible; EasouSpider; +http://www.easou.com/search/spider.html)

We can ask it to stop crawling us via robots.txt, but it would be better to deal with the root cause and not fail with 500 on those requests if possible.

We can't really reproduce this kind of request either, so any suggestions on how to generate a similar request would be of great help.

We're using Rails 3.2.19, Unicorn on Ubuntu 12.04. Here's our locale_middleware.rb

解决方案

Special thanks to Benjamin Sinclaire for pointing to the right issue on github.

The solution was described on this comment:

config.middleware.use ::Rack::Robustness do |g|
  g.no_catch_all
  g.on(ArgumentError) { |ex| 400 }
  g.content_type 'text/plain'
  g.body{ |ex| ex.message }
  g.ensure(true) { |ex| env['rack.errors'].write(ex.message) }
end

这篇关于神秘的轨道错误几乎没有痕迹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:08