![]() |
|
We don't bite newbies here... much | |
PerlMonks |
CGI Debugging: always the last place you look.by swngnmonk (Pilgrim) |
on Mar 05, 2004 at 21:27 UTC ( #334373=perlmeditation: print w/replies, xml ) | 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." WTF? 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. Finally, a break. "Try it in Lynx." Start the purchase process, get to the confirmation page. Wait... It's javascript.. Can't submit in Lynx.. What does the source show?? BINGO.
See it? The javascript was put in place so that the user's decision to purchase or cancel did not need to be determined by the runmode - the user would go right to the appropriate runmode. Unfortunately, the AHREF tag around it, under some browsers, causes the form to be submitted twice. *That* was the problem. The HTML had been written by a contractor ages ago. They had taken the bare-bones no-javascript template I had written (with working forms), and made it pretty. QA checked it under IE (where the form was submitted only once), it still worked. And sat there, lurking for months, until we finally did browser testing and it came up. Yowza. 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. I guess all I can say is question everything - up until I saw that javascript, it never occurred to me that some browsers could be sending two identical requests. And thank god for Lynx, which is always handy for bringing things into focus.
Back to
Meditations
|
|