Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails is making the same get request twice (update: only when I embed pinterest links on the page)

I have a rails 4.2.x app, wherein I notice that for each request I make, the logs show that the whole request is being sent twice - One request gets fully completed, the page seems fully rendered, but then another one starts again in the logs and runs through its course, and the second request has no visible effect in the client browser.

Started GET "/path/to/request" for 10.0.1.5 at 2016-04-12 21:23:08 +0530
<... bunch of SQL and other logs to fulfill this request...>
Completed 200 OK in 11487ms (Views: 11279.3ms | ActiveRecord: 40.3ms)

Started GET "/path/to/request" for 10.0.1.5 at 2016-04-12 21:23:21 +0530
<... same bunch of SQL and other logs ...>
Completed 200 OK in 8928ms (Views: 8899.3ms | ActiveRecord: 18.2ms)

This happens both on dev and production. It happens independent of browser

Based on suggestions on other SO threads and general hunches, I have tried:

  1. Removing all links that point to '#' and using
    'javascript:void(0)' instead
  2. Calling bundle exec rake assets:clobber
  3. In development.rb, set config.assets.prefix = '/dev-assets'
  4. Removing async: true from javascript_include_tag
  5. Tried calling from chrome incognito window
  6. Restarting browser
  7. Clearing the tmp folder with bundle exec rake tmp:clear
  8. Restarting the (dev) machine
  9. I do not have turbolinks in my Gemfile or Gemfile.lock

None of these seem to work. I am all out of options right now - any suggestions?

Update: turns out the culprit was embedded pinterest links on the page, when I remove it, the issue goes away - here is the source that caused it - how do I fix it to embed pinterest links and still not have multiple calls occur?

The url and script I put in the page for an embedded pin:

<a data-pin-do='embedPin' href='https://in.pinterest.com/pin/384143043191907516/'></a>

<script src="//assets.pinterest.com/js/pinit.js"></script>

Note: I also had async defer in the script as shown below (that is what the pinterest site recommends for embedding pinterest links), but keeping or removing them made no difference to the two request issue:

<script async defer src="//assets.pinterest.com/js/pinit.js"></script>

The page source that was generated by the script running:

<span class="PIN_1460479728283_embed_pin PIN_1460479728283_en" data-pin-log="embed_pin" data-pin-href="https://www.pinterest.com/pin/384143043191907516/" data-pin-id="384143043191907516"><span class="PIN_1460479728283_bd" data-pin-href="https://www.pinterest.com/pin/384143043191907516/" data-pin-log="embed_pin">
<span class="PIN_1460479728283_hd" data-pin-href="https://www.pinterest.com/pin/384143043191907516/" data-pin-log="embed_pin">     
<span class="PIN_1460479728283_container" data-pin-href="https://www.pinterest.com/pin/384143043191907516/" data-pin-log="embed_pin" style="padding-bottom: 154.43%;"><span class="PIN_1460479728283_img" data-pin-href="https://www.pinterest.com/pin/384143043191907516/" data-pin-log="embed_pin_img" data-pin-src="http://media-cache-ak0.pinimg.com/237x/f0/75/0b/f0750bea877d546aa4a95f52a9007cc8.jpg" style="background-image: url(&quot;http://media-cache-ak0.pinimg.com/237x/f0/75/0b/f0750bea877d546aa4a95f52a9007cc8.jpg&quot;);">
</span></span>
<span class="PIN_1460479728283_repin" data-pin-href="https://www.pinterest.com/pin/384143043191907516/" data-pin-log="embed_pin_repin" data-pin-id="384143043191907516"></span></span><span class="PIN_1460479728283_source" data-pin-href="http://guineapiggies.tumblr.com/post/62520038756/perlita-by-gabitayuz" data-pin-log="embed_pin_domain"><span class="PIN_1460479728283_img" data-pin-href="http://guineapiggies.tumblr.com/post/62520038756/perlita-by-gabitayuz" data-pin-log="embed_pin_domain" data-pin-src="http://media-cache-ec0.pinimg.com/favicons/09b6198f50d7e654ebb5f88e2016b83b0bb345386f0c4b685df4bacd.png?66c0426c45356a3c0afbd2cf5c32c99e" style="background-image: url(&quot;http://media-cache-ec0.pinimg.com/favicons/09b6198f50d7e654ebb5f88e2016b83b0bb345386f0c4b685df4bacd.png?66c0426c45356a3c0afbd2cf5c32c99e&quot;);"></span><span class="PIN_1460479728283_domain" data-pin-href="http://guineapiggies.tumblr.com/post/62520038756/perlita-by-gabitayuz" data-pin-log="embed_pin_domain">Guinea Piggies
</span>
<span class="PIN_1460479728283_menu" data-pin-href="http://guineapiggies.tumblr.com/post/62520038756/perlita-by-gabitayuz" data-pin-log="embed_pin_domain"><span class="PIN_1460479728283_toggle" data-pin-href="" data-pin-log="embed_pin_toggle"></span><span class="PIN_1460479728283_dropdown" data-pin-href="https://www.pinterest.com/about/copyright/dmca-pin/?id=384143043191907516" data-pin-log="embed_pin_report">Copyright issue
</span>
</span>
</span><span class="PIN_1460479728283_description" data-pin-href="https://www.pinterest.com/pin/384143043191907516/" data-pin-log="embed_pin">guinea pig</span><span class="PIN_1460479728283_stats" data-pin-href="https://www.pinterest.com/pin/384143043191907516/" data-pin-log="embed_pin"><span class="PIN_1460479728283_repins" data-pin-href="https://www.pinterest.com/pin/384143043191907516/repins/" data-pin-log="embed_pin">1</span></span></span><span class="PIN_1460479728283_ft" data-pin-href="https://www.pinterest.com/beblydia/" data-pin-log="embed_pin_pinner"><span class="PIN_1460479728283_img" data-pin-href="https://www.pinterest.com/beblydia/" data-pin-log="embed_pin_pinner" data-pin-src="http://media-cache-ak0.pinimg.com/avatars/beblydia_1447515585_60.jpg" style="background-image: url(&quot;http://media-cache-ak0.pinimg.com/avatars/beblydia_1447515585_60.jpg&quot;);"></span><span class="PIN_1460479728283_pinner" data-pin-href="https://www.pinterest.com/beblydia/" data-pin-log="embed_pin_pinner">Lydia Batista</span><span class="PIN_1460479728283_board" data-pin-href="https://www.pinterest.com/beblydia/guinea-pigs/" data-pin-log="embed_pin_board">Guinea pigs
</span></span></span>
like image 268
Anand Avatar asked Apr 12 '16 16:04

Anand


1 Answers

I had a similar issue before.. it was only happening in Chrome and I narrowed it down to there being an issue with turbolinks by adding

data-no-turbolink

to the body tag of my template. This stopped the issue, and specifically updating turbolinks

bundle update turbolinks

seemed to sort it all out. I hope this helps!

like image 63
Djwokian Avatar answered Oct 18 '22 20:10

Djwokian