|We don't bite newbies here... much|
CGI Debugging: always the last place you look.by swngnmonk (Pilgrim)
|on Mar 05, 2004 at 21:27 UTC||Need Help??|
While this is aimed at those monks writing CGI applications, this should be familiar to anyone suffering through the search for an obscure bug. As a preface - this isn't really a perl issue, as much as it is just one more story about the hell that is debugging.
We're in the final stages of testing a commerce application written w/ mod_perl, primarily based on CGI::Application. It's pretty straightforward stuff - user decides they want to buy something, they select the desired Credit Card to purchase with, they confirm or cancel the purchase, they get a thankyou page and an email if they confirm, cancel page otherwise.
Development has been somwhat scattershot lately - the project got pushed back in the schedule, we worked on other things, the final bits were added in a somewhat haphazard fashion. One of the last major bits of code that was added recently was responsible for those confirmation emails. Everything seemed fine.
In the earlier stages, our QA group was testing functionality, and was only using IE. In the last week, they started serious browser-testing, and that's when the strangest bug came in:
"When using Safari on the Mac, I click 'confirm purchase', and I get two confirmation emails. This works fine on the PC using IE."
So I test it on my own machine (Linux/Firefox). Sure enough, two emails!
I spend a *long* time looking at the code. No loops, no recursion, nothing that even remotely suggests things being called twice. I litter the appropriate runmode with plenty of debugging statements. Sure enough, it really is being called twice!
During all this time, the biggest mystery is this: only this runmode is affected. Every other runmode works perfectly. There has to be something wrong with this runmode!
Time to bring in the coworkers. Plenty of suggestions. What about the AccessHandler that you wrote? Nope. Is it really making two calls? Sure enough, dumping $$ into the error log shows two different Apache procs handling the request. "It's gotta be a redirect." Nope, not that either.
There's really not much of a moral to the story. Can't really blame anyone for it (yes, it was an HTML problem, but things *did* work on some levels). Can definitely slap my forehead as to how long it took to figure it out. Learned another debugging trick or two, which is always good.