1 November 2009 2 Comments

A Cautionary Tale of Woe: The Bug That Got Away

http://markbeljaars.com/wp-content/plugins/sociofluid/images/digg_48.png http://markbeljaars.com/wp-content/plugins/sociofluid/images/reddit_48.png http://markbeljaars.com/wp-content/plugins/sociofluid/images/stumbleupon_48.png http://markbeljaars.com/wp-content/plugins/sociofluid/images/delicious_48.png http://markbeljaars.com/wp-content/plugins/sociofluid/images/furl_48.png http://markbeljaars.com/wp-content/plugins/sociofluid/images/technorati_48.png http://markbeljaars.com/wp-content/plugins/sociofluid/images/facebook_48.png http://markbeljaars.com/wp-content/plugins/sociofluid/images/yahoobuzz_48.png http://markbeljaars.com/wp-content/plugins/sociofluid/images/mixx_48.png http://markbeljaars.com/wp-content/plugins/sociofluid/images/twitter_48.png

Last week I released an updated version of my Table of Contents Creator plugin for WordPress. I pride myself in my coding, fault finding and testing abilities. That all came crashing down in one single night.

To cut a long story short, the new revision required a helper function to display post entries. The helper function was only called by one function and I therefore elected to include the helper function as a child of that function. This is common practise in many languages as it neatly packages all functions and their helpers in close proximity. The parent function by the way is called every time a page is displayed and terminates immediately if that page does not include the site map initiator tag.

Ok. Time passes. It is now 2am. The code is now ready to test. I know that the parent function exits immediately if it doesn’t find the initiator tag. This has previously worked, and I went nowhere near it, so it should continue to work. Right? I check the site map page, try out all the new and old options and prove that the code is working as intended. I quickly synchronize the SVN repository and rush off to bed to get some sleep before the sun comes up.

Next morning I decide to check a large site I know that uses my plugin. There’s no substitute for real world testing. Yeah, it all looks good. At that point I noticed a post in the site map that looked interesting. I clicked on the category link and was presented with the first post in the category and then a big nasty php error message. Mmm. I looked at another large site. Mmm. Maybe a coincidence. Lets look at one more. Oh no!

So what went wrong? Remember that child function? I’ve heard it said that kids can be evil and it turned out to be true in this case. If a blog page, category page, tag page or even a home page was displayed, multiple posts are shown on a single page. WordPress does this by pretending that each post is a mini-page and links all the mini-pages together to form one large page. This means that my parent function is called multiple times. Normally not an issue. But now as the function contains child functions, these child functions are created each time the parent function is called (even if they are not used). Therefore, when then second post is displayed, the page crashes with a duplicate function name error message. The nett result was that a small bug in a seemingly unrelated function caused several very large websites to go down.

The morale of the story: if you are a website administrator, make sure you run the full suite of tests after every plugin update, no matter how big or small that plugin may be.

Related Posts

2 Responses to “A Cautionary Tale of Woe: The Bug That Got Away”

  1. Nicolas 17 November 2009 at 12:41 pm #

    Thank you! I would now go on this blog every day!
    Have a nice day
    Nicolas


Trackbacks/Pingbacks.

  1. The Bug That Got Away - 20. Nov, 2009

    [...] from: The Bug That Got Away Comments0 Leave a Reply Click here to cancel [...]

Leave a Reply


SpinChimp Leaderboard 728x90