Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails app logging duplicate requests

I have a Rails app that is generating duplicate requests for every request in development. The app is running Rails 2.3.5 with my primary development machine running Ubuntu 10.4. However, the same code runs fine without showing duplicate requests on my OS X 10.6 box. It also runs in Production mode on either machine without problems.

  Processing DashboardController#index (for 127.0.0.1 at 2010-07-16 10:23:08) [GET]
  Parameters: {"action"=>"index", "controller"=>"dashboard"}
Rendering template within layouts/application
Rendering dashboard/index
  Term Load (1.9ms)   SELECT * FROM "date_ranges" WHERE ('2010-07-16' BETWEEN begin_date and end_date ) AND ( ("date_ranges"."type" = 'Term' ) ) 
  StaticData Load (1.1ms)   SELECT * FROM "static_data" WHERE ("static_data"."name" = E'SITE_NAME') LIMIT 1
  CACHE (0.0ms)   SELECT * FROM "static_data" WHERE ("static_data"."name" = E'SITE_NAME') LIMIT 1
Rendered dashboard/_news (0.1ms)
  CACHE (0.0ms)   SELECT * FROM "static_data" WHERE ("static_data"."name" = E'SITE_NAME') LIMIT 1
  CACHE (0.0ms)   SELECT * FROM "static_data" WHERE ("static_data"."name" = E'SITE_NAME') LIMIT 1
  StaticData Load (0.9ms)   SELECT * FROM "static_data" WHERE ("static_data"."name" = E'TAG_LINE') LIMIT 1
Completed in 67ms (View: 58, DB: 5) | 200 OK [http://localhost/dashboard]
  SQL (0.4ms)   SET client_min_messages TO 'panic'
  SQL (0.4ms)   SET client_min_messages TO 'notice'


Processing DashboardController#index (for 127.0.0.1 at 2010-07-16 10:23:08) [GET]
  Parameters: {"action"=>"index", "controller"=>"dashboard"}
Rendering template within layouts/application
Rendering dashboard/index
  Term Load (1.9ms)   SELECT * FROM "date_ranges" WHERE ('2010-07-16' BETWEEN begin_date and end_date ) AND ( ("date_ranges"."type" = 'Term' ) ) 
  StaticData Load (1.1ms)   SELECT * FROM "static_data" WHERE ("static_data"."name" = E'SITE_NAME') LIMIT 1
  CACHE (0.0ms)   SELECT * FROM "static_data" WHERE ("static_data"."name" = E'SITE_NAME') LIMIT 1
Rendered dashboard/_news (0.1ms)
  CACHE (0.0ms)   SELECT * FROM "static_data" WHERE ("static_data"."name" = E'SITE_NAME') LIMIT 1
  CACHE (0.0ms)   SELECT * FROM "static_data" WHERE ("static_data"."name" = E'SITE_NAME') LIMIT 1
  StaticData Load (0.9ms)   SELECT * FROM "static_data" WHERE ("static_data"."name" = E'TAG_LINE') LIMIT 1
Completed in 67ms (View: 58, DB: 5) | 200 OK [http://localhost/dashboard]
  SQL (0.4ms)   SET client_min_messages TO 'panic'
  SQL (0.4ms)   SET client_min_messages TO 'notice'

Notice that the requests are exactly the same, even down to the timestamps.

I have tried using Ruby 1.8.7 & 1.9.1 as well as swapping between Mongrel & Webrick and it always processes each request twice (or at least it generates two log entries). I tried removing most of the routes to see if I had something weird going on, but the problem persists. I tried different browsers (Chrome, Safari, eLinks) from different machines to see if that would help, but the problem persists. I removed all of my gems and only replaced the necessary ones but to no avail.

Does anyone have any idea why Rails would cause duplicate requests like this? I am about at my wits end and am grasping at straws. The only bright spark is that this behavior does not happen under the Production environment, only Development.

like image 819
Richard Hurt Avatar asked Jul 16 '10 14:07

Richard Hurt


7 Answers

When people come to this question from google it's important they disambiguate their problem between duplicate logs that look like this:

A
A
B
B
C
C

From duplicate logs that look like this:

A
B
C

A
B
C

The former is likely from duplicate LOGGING. The later is likely from duplicate REQUESTS. In the case it is the latter as shown by the Question Asker (OP), you should strongly consider @www's answer of hunting down a <img src="#"> or a similar self-referential url tag. I spent hours trying to figure out why my application was appearing to make two duplicate requests, and after reading @www's answer (or @aelor's on Double console output?), I found

%link{href: "", rel: "shortcut icon"}/

in my code! It was causing every page of my production app to be double rendering!!!! So bad for performance and so annoying!

like image 92
Sean Ahrens Avatar answered Oct 06 '22 00:10

Sean Ahrens


Check your code see if there is something like this inside it:

I have got the same problem just now becase of a tag

<img src="#">

this will cause rails to make duplicate requests!

like image 35
www Avatar answered Oct 05 '22 23:10

www


This was happening to me in rails 4.2.3 after installing the heroku rails_12factor gem which depends on rails_stdout_logging

like image 21
Jose Avatar answered Oct 05 '22 22:10

Jose


The "answer" to the problem was to move to a new directory and fetch the original code from Github. After getting everything configured and setup in the new directory the application works as it should with no duplicate requests. I still don't know why the code in the original directory borked out; I even diff'ed the directories and the only outliers were the log files.

I'm answering my own question here for the sanity of others that might experience the same problem.

like image 24
Richard Hurt Avatar answered Oct 05 '22 23:10

Richard Hurt


I resolved this problem by commenting the following line in app/config/environments/development.rb:

config.middleware.use Rails::Rack::LogTailer

I do not remember exactly the reason to use this setting

like image 23
Thiago Silva Avatar answered Oct 05 '22 23:10

Thiago Silva


I solve this same problem here by cleaning all precompiled assets with: rake assets:clean

I've tried to delete the app folder and then checkout him back from GitHub but didnt work.

hope this help. thanks.

like image 23
Rudiney Franceschi Avatar answered Oct 06 '22 00:10

Rudiney Franceschi


This started happening to me on development after playing around with some custom middleware I wrote. Running rake assets:clean:all solved it.

like image 24
Ady Rosen Avatar answered Oct 06 '22 00:10

Ady Rosen