简体   繁体   English

机架中间件死锁

[英]Rack middleware deadlock

I include this simple Rack Middleware in a Rails application: 我在Rails应用程序中包含这个简单的Rack Middleware:

class Hello

  def initialize(app)
    @app = app
  end

  def call(env)
    [200, {"Content-Type" => "text/html"}, "Hello"]
  end

end

Plug it in inside environment.rb: 将其插入environment.rb:

...
Dir.glob("#{RAILS_ROOT}/lib/rack_middleware/*.rb").each do |file|
  require file
end
Rails::Initializer.run do |config|
  config.middleware.use Hello
...

I'm using Rails 2.3.5, Webrick 1.3.1, ruby 1.8.7 我正在使用Rails 2.3.5,Webrick 1.3.1,ruby 1.8.7

When the application is started in production mode, everything works as expected - every request is intercepted by the Hello middleware, and "Hello" is returned. 当应用程序在生产模式下启动时,一切都按预期工作 - 每个请求都被Hello中间件拦截,并返回“Hello”。 However, when run in development mode, the very first request works returning "Hello", but the next request hangs. 但是,在开发模式下运行时,第一个请求会返回“Hello”,但下一个请求会挂起。

Interrupting webrick while it is in the hung state yields this: 在处于挂起状态时中断webrick会产生以下结果:

^C[2010-03-24 14:31:39] INFO  going to shutdown ...
deadlock 0xb6efbbc0: sleep:-  - /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:31
deadlock 0xb7d1b1b0: sleep:J(0xb6efbbc0) (main) - /usr/lib/ruby/1.8/webrick/server.rb:113
Exiting
/usr/lib/ruby/1.8/webrick/server.rb:113:in `join': Thread(0xb7d1b1b0): deadlock (fatal)
 from /usr/lib/ruby/1.8/webrick/server.rb:113:in `start'
 from /usr/lib/ruby/1.8/webrick/server.rb:113:in `each'
 from /usr/lib/ruby/1.8/webrick/server.rb:113:in `start'
 from /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
 from /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
 from /usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/webrick.rb:14:in `run'
 from /usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:111
 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
 from /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
 from script/server:3

Something to do with the class reloader in development mode. 与开发模式中的类重新加载器有关。 There is also mention of deadlock in the exception. 在例外中还提到了死锁。

Any ideas what might be causing this? 可能导致这种情况的任何想法? Any recommendations as to the best approach to debug this? 有关调试此方法的最佳方法的任何建议吗?

UPDATE UPDATE

$ script/console 
Loading development environment (Rails 2.3.5)
>> app.get '/'
=> 200
>> app.get '/'
ThreadError: stopping only thread
 note: use sleep to stop forever
 from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:31:in `lock'
 from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/reloader.rb:31:in `run'
 from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dispatcher.rb:108:in `call'
 from /usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lint.rb:47:in `_call'
 from /usr/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lint.rb:35:in `call'
 from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/integration.rb:316:in `process'
 from /usr/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/integration.rb:197:in `get'
 from (irb):2

Looks like it might be related to this issue: 看起来它可能与此问题有关:

https://rails.lighthouseapp.com/projects/8994/tickets/3153-actioncontrollerintegrationsession-broken-in-234 https://rails.lighthouseapp.com/projects/8994/tickets/3153-actioncontrollerintegrationsession-broken-in-234

I've come up with a hack that will get me by the time being. 我想出了一个能够让我暂时离开的黑客。 It's on the ticket mentioned above. 它在上面提到的机票上。

https://rails.lighthouseapp.com/projects/8994/tickets/3153-actioncontrollerintegrationsession-broken-in-234 https://rails.lighthouseapp.com/projects/8994/tickets/3153-actioncontrollerintegrationsession-broken-in-234

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM