pumpsoft has asked for the wisdom of the Perl Monks concerning the following question:

In slashcode's Slash::Display there is a sub slashDisplay that has near the end a line that outputs some HTML:
print $out unless $opt->{Return};
On my system, and apparently some others, this line hangs the sub, which in turn hangs everything up the calling tree and results in the slashd daemon being unable to continue processing tasks due to freshenup.pl not completing. (This is on a Athlon RedHat 7.3 box, I've tried a vanilla setup of mysql/perl/apache, and I've also tried a similar box with these things compiled from scratch with slashcode in mind.)

the slashDisplay sub gets called for just about everything in slashcode to generate HTML from templates, and it usually works fine. But this hang is 100% reproducable on my systems and I'm out of ideas for how to make it go away. It only happens when a new article is posted, that's the only time freshenup.pl takes this particular path. Even so, slashDisplay is getting called multiple times during this, iterating through all the individual templates without problems. It's not until it gets to the last call and $out is printed (instead of returned) that it just... hangs. Killing the script process manually allows the scripts to complete normally, and $out _does_ apparently get printed, but the print statement never returns. If I add lines immediately before this thusly:
open TMPOUT, ">/tmp/tmpout"; print TMPOUT $out; close TMPOUT
The output gets written to the file just fine. It only seems to hang if it's going to the default STDOUT. I've tried turning buffering off and other things that had no effect, and stupid stuff like using different variable names, copying into a new scalar, etc. I don't think it's a slash problem per se, it seems like more of a perl problem or my environment. I'm using perl 5.6.1 and modules were installed via CPAN. I can't use slash until I get this fixed, and I'm lost.

Fixed code tags - dvergin 2002-06-10

Replies are listed 'Best First'.
Re: print $out doesn't always?
by Abigail-II (Bishop) on Jun 11, 2002 at 12:36 UTC
    I find it unlikely it's a Perl problem. Where is STDOUT going to? Is it redirected to a resource that has problems? (pipe, file, socket?) What happens if you change the print to a warn? Did you run it from the command line, or do you only have problems with it when running from Apache?

    Abigail

      The way I understand it, here's the way it's supposed to work...

      The slashd script is running as a daemon, it calls various housekeeping scripts periodically. The freshenup.pl script gets called by slashd. freshenup.pl contains a call to prog2file() which is used to execute a script and direct the output to a file. prog2file() is executing the script with this line:
      $data = `$exec`;
      thus capturing the output of the command in a variable which it prints to a file later. The value of $exec at runtime is valid and intended to run article.pl with appropriate arguments.

      article.pl runs, and in turn results in a call to index.pl to update the index. index.pl calls slashDisplay() several times and receives the output as a returned value. index.pl then calls slashDisplay() again to print the output instead of return the output. It is this line that is hanging.

      So I think the calling order is:

      slashd
      freshenup.pl
      prog2file()
      article.pl()
      index.pl()

      I can run index.pl from the command line using the same arguments with no problem. As far as I see, STDOUT isn't being redirected to any file or socket, etc. I think it's supposed to get to the parent script, and so on up the tree. It's the prog2file() sub that uses the backtick form of the system() command to capture the output of all the children into a scalar and print it to a file.

      I'm not fluent enough in this yet to know how to accurately trace the STDOUT path here. I'm told perhaps the parent's pipe has stalled, but I don't know how to investigate that. I didn't write this code, of course, and it's my significant first exposure to perl programming. (slashcode probably isn't the best thing to cut my perl teeth on, but that's the way it's working out!)