2

我在 Heroku 服务器上使用 Ruby 为 Facebook 编写了一个应用程序,一切都很顺利,直到我将 dynos 的数量增加到 2。此时,大约有一半的时间我去一个新页面,我会得到一个错误消息,或者我会返回到主页,这取决于我去了哪个页面。我通过返回一个测功机解决了这个问题,但我仍然不知道出了什么问题。有任何想法吗?代码可以在这里找到:

https://github.com/runninggraeb/toolshed

该程序可以在这里找到(如果您有兴趣):

https://apps.facebook.com/toolshed

任何帮助,将不胜感激。

所有日志都粘贴在下面。请注意,错误消息是在我使用 dyno=web.1,然后是 dyno=web.2 之后开始的。

2013-03-10T22:34:54+00:00 heroku[router]: at=info method=GET path=/auth/facebook host=toolshed.herokuapp.com fwd="24.20.19.205" dyno=web.2 queue=0 wait=7ms connect=5ms service=10ms status=302 bytes=0
2013-03-10T22:34:57+00:00 app[web.1]: 24.20.19.205 - - [10/Mar/2013 22:34:57] "GET /auth/facebook/callback?code=AQC7B6vjC0ksefFLly76DMeqL-hHrR6M49lYgMqiAk01xmF-nbXC9pOAcd_e5x8KTycXcjfXG_ABRUmsfeQlusGECbL7d4PqF-nTIVMA1GBn8hAemVCBKXy8sUspQ1eIZAxICtYeSUk9DzM8-It9-AAbi0FudCRS8PkcTaZ-8SXnNYRk2-iYKMin_fYUG2kT8LbApmaeb1RjtxXQUF8HbvAu HTTP/1.1" 302 - 0.0724
2013-03-10T22:34:57+00:00 app[web.1]: 24.20.19.205 - - [10/Mar/2013 22:34:57] "GET / HTTP/1.1" 200 6836 0.2166
2013-03-10T22:34:57+00:00 heroku[router]: at=info method=GET path=/ host=toolshed.herokuapp.com fwd="24.20.19.205" dyno=web.1 queue=0 wait=9ms connect=15ms service=235ms status=200 bytes=6836
2013-03-10T22:35:01+00:00 app[web.2]: NoMethodError - undefined method `length' for nil:NilClass:
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:708:in `block (2 levels) in route!'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:755:in `catch'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:755:in `process_route'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:758:in `block in process_route'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:808:in `block in invoke'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:268:in `block in perform_action_with_newrelic_trace'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:808:in `catch'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:644:in `block in call!'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:808:in `invoke'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:808:in `instance_eval'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/app.rb:86:in `block in <top (required)>'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152:in `call'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1152:in `block in compile!'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:724:in `instance_eval'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:706:in `each'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:706:in `route!'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:724:in `route_eval'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:843:in `dispatch!'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.2/lib/rack/head.rb:9:in `call'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/instrumentation/sinatra.rb:48:in `block in dispatch_with_newrelic'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/instrumentation/sinatra.rb:47:in `dispatch_with_newrelic'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1303:in `synchronize'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/newrelic_rpm-3.5.4.33/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:263:in `perform_action_with_newrelic_trace'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:707:in `block in route!'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/thin-1.2.11/lib/thin/connection.rb:84:in `block in pre_process'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1272:in `block in call'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/thin-1.2.11/lib/thin/connection.rb:82:in `catch'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.2/lib/rack/commonlogger.rb:20:in `call'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:644:in `call!'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:629:in `call'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.2/lib/rack/session/abstract/id.rb:190:in `call'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/thin-1.2.11/lib/thin/connection.rb:57:in `process'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.2/lib/rack/methodoverride.rb:24:in `call'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.2.6/lib/sinatra/base.rb:1272:in `call'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/thin-1.2.11/lib/thin/connection.rb:82:in `pre_process'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/thin-1.2.11/lib/thin/controllers/controller.rb:86:in `start'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/thin-1.2.11/lib/thin/backends/base.rb:61:in `start'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/thin-1.2.11/lib/thin/runner.rb:185:in `run_command'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/bin/thin:19:in `load'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/thin-1.2.11/lib/thin/server.rb:159:in `start'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/rack-1.3.2/lib/rack/session/abstract/id.rb:195:in `context'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/thin-1.2.11/lib/thin/runner.rb:151:in `run!'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/thin-1.2.11/lib/thin/connection.rb:42:in `receive_data'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/bin/thin:19:in `<main>'
2013-03-10T22:35:01+00:00 app[web.2]:  /app/vendor/bundle/ruby/1.9.1/gems/thin-1.2.11/bin/thin:6:in `<top (required)>'
2013-03-10T22:35:01+00:00 app[web.2]: 24.20.19.205 - - [10/Mar/2013 22:35:01] "GET /friends_tools.html HTTP/1.1" 500 30 0.1515
2013-03-10T22:35:01+00:00 heroku[router]: at=info method=GET path=/friends_tools.html host=toolshed.herokuapp.com fwd="24.20.19.205" dyno=web.2 queue=0 wait=0ms connect=4ms service=156ms status=500 bytes=30
4

1 回答 1

0

该问题仅在超过一个测功机时才会出现这一事实表明它可能是一个共享状态问题。即用户在 dyno-1 上进行身份验证,并且会话 ID 存储在 dyno-1 上的内存中。同一用户的下一个请求是 dyno-2 的服务器,它不知道会话并炸毁了。这是纯粹的猜想,我还没有检查过你的代码。

或者,这个 Sinatra 问题有一个与 New Relic 类似的错误,并建议升级到 New Relic 问题的预发布版本可以解决该问题。

于 2013-03-11T05:12:44.660 回答