This Time Self-Hosted
dark mode light mode Search

A déjà vu is usually a glitch in the… Rails?

All of you who read my blog through Gentoo Universe and either Google Reader or Liferea (not sure about other feed readers) will probably have noticed that over the last few months my post appeared duplicated as “new” from time to time. I have had this reported quite a few times but I couldn’t find any reason why that happened; each time the feed looked in order for me.

Thankfully, there are people with more attention to details than me, and Torsten found the one difference between the two feeds: the <id> tag reported blog.flameeyes.eu first and farragut.flameeyes.is-a-geek.org afterwards. You probably remember the latter as my original URL for the blog, and the one that, some time ago, I restored for access without adding further redirects. And that was a bad idea, as it happens.

The problem here is actually multi-layered, and that shows why the problem happens only on Gentoo Universe (and not Planet Gentoo). First of all, while Typo publishes feed for each category and each tag, the default feed (everything), and the Gentoo-specific one are wrapped in FeedBurner; the reason was mostly reducing the bandwidth spent on serving these feeds to subscribers, given that more than a couple of time I had people using broken feed-fetchers with one minute refresh time, and no If-Modified-Since, If-None-Match support which meant serving the same feed, well, too many times.

In this situation, the feed as seen by Planet Gentoo and that seen by any other requester is quite different, as the former is whitelisted not to be redirected to FeedBurner; this made it totally safe. Unfortunately, the same wasn’t true of the English category I use to skip over Italian posts on Gentoo Universe (by policy), so the same feed requested by users was the one given to the Venus software.

Since, starting September, I did allow straight requests without redirection between the old hostnames on the flameeyes.is-a-geek.org domain and the new ones, the requests on the feed for people who subscribed a long time ago appeared with both domains in the requests. Again, this is nothing particularly strange and nothing I’d expect to cause problem, if it wasn’t for Rails.

But before reaching Rails, my first thought was to check out the Typo source code; I was expecting to find there the source for the Atom feeds, and indeed a file that was at some point used to build the Atom feed was there; unfortunately that file is totally unlinked to all the rest nowadays, as ActionPack (2.3.8) takes care of the basis of Atom feed generation. This unfortunately means that it’s too generic to know about the Typo-configured canonical URL for the blog.

Indeed the code generating the start of the feed itself contains this:

        xml.feed(feed_opts) do
          xml.id(options[:id] || "tag:#{request.host},#{options[:schema_date]}:#{request.request_uri.split(".")[0]}")

You can see here what the problem is: request.host will make the feed content change between one request and the other depending on the URL used to reach the application. So what? Given Venus will always request the feed on the same URL it would receive always the same output! Yes that would be the default, if Typo wasn’t being smart slightly more than Rails is and wasn’t thus caching the results. But it is, and rightfully so most of the time because unless I’m posting something, changing the theme, or somebody comments, the blog’s pages are mostly static.

Unfortunately, by caching the results, the saved copy of the feed will cause requests coming from the two domains to have the same tag base: that of the latest request which was cache, which could very well be the “wrong” one. And for software that tracks down the posts by their reported IDs, such as Venus, this is quite a bother.

To solve the problem, so that you’re not further bothered by my posts appearing twice, I’ve restored the redirect and dropped the replies coming from the alias, although that bothers me a bit. As it turns out, it is not safe to run a Rails web application to answer to more than a single vhost, at least as of 2.3.8 (I haven’t upgraded to 2.3.10 because of some trouble with Typo 5, and I sure don’t want to update to Typo 6/Rails 3 any time soon).

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.