gpt4 book ai didi

ruby-on-rails - Rack 中间件死锁

转载 作者:行者123 更新时间:2023-12-02 05:14:08 27 4
gpt4 key购买 nike

我在 Rails 应用程序中包含了这个简单的 Rack 中间件:

class Hello

def initialize(app)
@app = app
end

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

end

将其插入到 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
...

我正在使用 Rails 2.3.5、Webrick 1.3.1、ruby 1.8.7

当应用程序在生产模式下启动时,一切都按预期工作 - 每个请求都被 Hello 中间件拦截,并返回“Hello”。然而,当在开发模式下运行时,第一个请求可以返回“Hello”,但下一个请求会挂起。

在 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

与开发模式下的类重新加载器有关。异常中也提到死锁。

知道是什么原因造成的吗?关于最佳调试方法的任何建议?

更新

$ 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

看起来可能与这个问题有关:

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

最佳答案

我想出了一个 hack,可以暂时得到我的帮助。在上面提到的票上。

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

关于ruby-on-rails - Rack 中间件死锁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2505182/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com