« Internet2 Connection | Main | Development Thrashing »

February 18, 2003

Today's Challenge: Debug Embperl

Today's challenge is debugging an Embperl file. Embperl is somewhat like PHP in that with some special syntax you can move between HTML and Perl with ease. We use Embperl on top of our Perl libraries, purely as an HTML templating engine.

The problem: on this particular page perl core dumps on every nth request, n being the number of Apache processes running. The file is ~500 lines with around 100 calls to Perl the libraries, primarily to get lists of objects to format in HTML. The core dump doesn't appear to be coming from the underlying libraries because we use them on all our other pages without issue, and the fact that Embperl is successful on most of the requests makes me think there is something within the Embperl.

I have hopes that this script, embpexec.pl, that comes with embperl will enable me to get deeper into the problem. I have attempted so far to debug over the web, but am getting useless information. I have tried a few things that we've had trouble with before (variable scoping, missing header variables) but to no avail.

Running the Embperl page on the command line shows no problems, which means that the trouble is executing the page in the Apache environment. Possibly some trouble with the request object. Will start at the top and work through block by block using exit() to end early and hopefully pinpoint the trouble block.

This has drug on for several days now, it took a full day just to get a test that failed in a predictable way. After that I turned on a buttload of logging with this option in httpd.conf:

PerlSetEnv EMBPERL_LOG $server_root/logs/embperl_log

This logged all of Embperls actions and flushed out to the log file on every action. This allowed me to pinpoint a few things that were happening in the Embperl. Bottom line, some experimental syntax had been used and it was causing Embperl to misparse the page.

Embperl allows you to specify a process block which will retain scope across multiple blocks using [* *]. We couldn't figure out exactly what was happening, but since these blocks could also be processed with [$ $] we switched them and the problem dissappeared.

I also found that in a few places Embperl variables were acting differently based on what was passed through the Apache process on the last request. Found myself making sure that all variables were declared explicitly before use to prevent problems with data hanging around from a previous request.

I both hated and liked the experience. Hated because it was a week wasted, liked it because a very troubling problem has gone away.

Posted by mike at February 18, 2003 2:59 PM