我在JRuby上运行一个简单的DataMapper / Sinatra应用程序作为搜索服务。我在搜索时收到零星的错误消息(无法找到特定的押韵或原因),想知道是否有其他人遇到过类似的问题。
错误随机发生,本身也不一致。
示例:
INFO: IOError - closed stream:
org/jruby/RubyIO.java:2616:in `sysread'
/usr/lib/jruby/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'
org/jruby/ext/Timeout.java:99:in `timeout'
/usr/lib/jruby/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
/usr/lib/jruby/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
/usr/lib/jruby/lib/ruby/1.8/net/protocol.rb:126:in `readline'
/usr/lib/jruby/lib/ruby/1.8/net/http.rb:2026:in `read_status_line'
/usr/lib/jruby/lib/ruby/1.8/net/http.rb:2015:in `read_new'
/usr/lib/jruby/lib/ruby/1.8/net/http.rb:1051:in `request'
/usr/lib/jruby/lib/ruby/1.8/net/http.rb:1037:in `request'
/usr/lib/jruby/lib/ruby/1.8/net/http.rb:543:in `start'
/usr/lib/jruby/lib/ruby/1.8/net/http.rb:1035:in `request'
/usr/lib/jruby/lib/ruby/1.8/net/http.rb:772:in `get'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/rsolr-0.12.1/lib/rsolr/connection/net_http.rb:16:in `get'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/rsolr-0.12.1/lib/rsolr/connection/requestable.rb:36:in `request'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/rsolr-0.12.1/lib/rsolr/client.rb:34:in `request'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/sunspot-1.2.1/lib/sunspot/search/abstract_search.rb:35:in `execute'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/sunspot-1.2.1/lib/sunspot/session.rb:59:in `search'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/sunspot-1.2.1/lib/sunspot.rb:335:in `search'
/var/www/search/application.rb:7:in `HEAD /search'
INFO: NoMethodError - undefined method `+' for nil:NilClass:
/usr/lib/jruby/lib/ruby/1.8/net/protocol.rb:178:in `write0'
/usr/lib/jruby/lib/ruby/1.8/net/protocol.rb:153:in `write'
/usr/lib/jruby/lib/ruby/1.8/net/protocol.rb:168:in `writing'
/usr/lib/jruby/lib/ruby/1.8/net/protocol.rb:152:in `write'
/usr/lib/jruby/lib/ruby/1.8/net/http.rb:1580:in `write_header'
/usr/lib/jruby/lib/ruby/1.8/net/http.rb:1535:in `exec'
/usr/lib/jruby/lib/ruby/1.8/net/http.rb:1049:in `request'
/usr/lib/jruby/lib/ruby/1.8/net/http.rb:772:in `get'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/rsolr-0.12.1/lib/rsolr/connection/net_http.rb:16:in `get'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/rsolr-0.12.1/lib/rsolr/connection/requestable.rb:36:in `request'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/rsolr-0.12.1/lib/rsolr/client.rb:34:in `request'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/sunspot-1.2.1/lib/sunspot/search/abstract_search.rb:35:in `execute'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/sunspot-1.2.1/lib/sunspot/session.rb:59:in `search'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/sunspot-1.2.1/lib/sunspot.rb:335:in `search'
/var/www/search/application.rb:7:in `HEAD /search'
INFO: IOError - stream closed:
org/jruby/RubyIO.java:1978:in `close'
/usr/lib/jruby/lib/ruby/1.8/net/protocol.rb:70:in `close'
/usr/lib/jruby/lib/ruby/1.8/net/http.rb:1059:in `request'
/usr/lib/jruby/lib/ruby/1.8/net/http.rb:772:in `get'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/rsolr-0.12.1/lib/rsolr/connection/net_http.rb:16:in `get'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/rsolr-0.12.1/lib/rsolr/connection/requestable.rb:36:in `request'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/rsolr-0.12.1/lib/rsolr/client.rb:34:in `request'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/sunspot-1.2.1/lib/sunspot/search/abstract_search.rb:35:in `execute'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/sunspot-1.2.1/lib/sunspot/session.rb:59:in `search'
/usr/lib/jruby-1.6.0/lib/ruby/gems/1.8/gems/sunspot-1.2.1/lib/sunspot.rb:335:in `search'
/var/www/search/application.rb:7:in `HEAD /search'
错误似乎是Sunspot(RSolr或JRuby可能?)下面的问题,但我有点不知所措,因为我无法找到一种方法来始终如一地重现问题。我已经尝试过屠杀Solr安装请求,看看它是否与Solr / Tomcat有问题,但我还没有抓住Solr / Tomcat丢球。
答案 0 :(得分:2)
问题在于线程化。默认情况下,Sunspot的会话对象不是线程安全的。在Sunspot :: Rails中,它默认使用线程安全对象,但由于这是Sinatra,您必须手动执行此操作,如下所示:
Sunspot.session = Sunspot::SessionProxy::ThreadLocalSessionProxy.new(Sunspot.config)