我使用Spree的Rails有非常奇怪的問題。Rails處理每個請求兩次
每個請求正在處理兩次。 AJAX沒有問題,因爲單個CURL請求也會被處理兩次。日誌也不是問題,因爲行爲確實發生了兩次。
問題僅存在於Heroku和本地的生產環境中。
實例日誌:
2014-04-06T06:45:48.969394+00:00 heroku[router]: at=info method=POST path=/spree/api/orders/R657018514/line_items host=xxx.xxx.com request_id=75ac3584-f33e-48fe-b6ce-d898120f8b57 fwd="185.12.21.77" dyno=web.1 connect=0ms service=399ms status=201 bytes=1097
2014-04-06T06:45:48.952672+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/bundler/gems/spree-78f129b6d6f5/api/app/views/spree/api/orders/show.v1.rabl (120.9ms)
2014-04-06T06:45:48.959453+00:00 app[web.1]: Completed 201 Created in 381ms (Views: 93.4ms | ActiveRecord: 188.8ms)
2014-04-06T06:45:48.959460+00:00 app[web.1]: Completed 201 Created in 381ms (Views: 93.4ms | ActiveRecord: 188.8ms)
2014-04-06T06:45:48.958355+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/bundler/gems/spree-78f129b6d6f5/api/app/views/spree/api/orders/show.v1.rabl (120.9ms)
Started GET "/" for 127.0.0.1 at 2014-04-06 08:55:29 +0200
Started GET "/" for 127.0.0.1 at 2014-04-06 08:55:29 +0200
Processing by Spree::HomeController#index as HTML
Processing by Spree::HomeController#index as HTML
Rendered spree/home/index.html.erb within spree/layouts/spree_application (0.8ms)
Rendered spree/home/index.html.erb within spree/layouts/spree_application (0.8ms)
Gemfile.rb:
source 'https://rubygems.org'
gem 'rails', '4.0.3'
gem 'newrelic_rpm'
group :assets do
gem 'sass-rails', '~> 4.0.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'compass', '= 0.12.2'
gem 'compass-rails', '~> 1.1.2'
gem 'uglifier', '>= 1.0.3'
end
group :development do
gem 'sqlite3'
gem 'pry-rails'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
gem 'jquery-rails', '~> 3.1.0'
gem 'jquery-ui-rails'
gem 'handlebars_assets'
gem 'spree', :github => "methyl/spree", :require => false
gem 'spree_auth_devise', github: 'spree/spree_auth_devise'
production.rb
Aimer::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_assets = true
config.static_cache_control = "public, max-age=31536000"
# Compress JavaScripts and CSS
config.assets.compress = true
# Don't fallback to assets pipeline if a precompiled asset is missed
config.assets.compile = true
# Generate digests for assets URLs
config.assets.digest = true
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
# Defaults to nil and saved in location specified by config.assets.prefix
# config.assets.manifest = YOUR_PATH
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
config.force_ssl = false
# See everything in the log (default is :info)
# config.log_level = :debug
# Prepend all log lines with the following tags
# config.log_tags = [ :subdomain, :uuid ]
# Use a different logger for distributed setups
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
# Use a different cache store in production
# config.cache_store = :mem_cache_store
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
# config.assets.precompile += %w(search.js)
# Disable delivery errors, bad email addresses will be ignored
# config.action_mailer.raise_delivery_errors = false
# Enable threaded mode
# config.threadsafe!
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation can not be found)
config.i18n.fallbacks = true
# Send deprecation notices to registered listeners
config.active_support.deprecation = :notify
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
# config.active_record.auto_explain_threshold_in_seconds = 0.5
end
你怎麼知道這不是日誌?我發現有兩個請求具有完全相同的渲染時間是非常不可能的,對於所有請求,情況如何? – Giannis
我收到兩次電子郵件,AFAIK它是爲每個請求。 – methyl
不僅日誌條目顯示*確切*相同的處理時間,其中兩個已在7微秒內寫入對方。無論問題是什麼,所顯示的代碼都不會涵蓋它。我可能會懷疑偶然的對某些中間件組件的雙重調用,可能是因爲註冊了兩次。 –