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

Hi. I have a question that's been bothering me for quite a while. I'm running the app Bugzilla on an Apache server. If you're not familiar with Bugzilla, it's a web based tool that lets you track bugs in a software application (using Perl/CGI and the mySQL database). When my users try to search the bugs using the Perl/CGI interface, they select their search parameters and press submit. The query either goes through cleanly with no problems at all, or they are given a 500 Internal Server Error. If they just press Refresh, the page will generate correctly 99% of the time with the correct query results. The other 1% they have to press Refresh one or two more times, but it will always come back with the correct results. I've had them clear their cache numerous times and am at my wit's end. I don't know what could be causing the Internal Server Error, and why it works by just refreshing the page. This has been most frustrating for them, and moreso for me since I can't explain it.

Here are the errors that I see in the error log when I get the 500 Internal Server Error:

[Mon Oct 21 08:04:14 2002] [error] [client 172.26.21.54] Premature end + of script headers: /usr/local/bugzilla-2.14.1/buglist.cgi [Mon Oct 21 08:04:17 2002] [error] [client 172.26.21.54] Premature end + of script headers: /usr/local/bugzilla-2.14.1/buglist.cgi

As you can tell, Refresh was pressed twice for this one. :) I'm familiar with the "Premature end of script headers" error, and I've looked at the code to make sure it's always printing out the "Content-type: text/html" header with two line breaks afterwards. This is done before any printing to the screen is done. And like I said, if I refresh it usually comes back ok.

Any ideas?

Thanks,
Trent

2002-10-28 Edit by Corion : Added code tags

Replies are listed 'Best First'.
Re: Perl 500 Internal Server Error
by mfriedman (Monk) on Oct 28, 2002 at 22:02 UTC
    This type of thing usually happens if the script dies unexpectedly before sending the headers. I'm not very familiar with Bugzilla, so I don't know what would necessarily be causing that. Because you mentioned it only happens occasionally, it will likely be a difficult problem to track down. Does Mozilla do any logging of its own? If so, you might want to turn it on and set it to the highest available level. If not, you may want to go through the code and print status messages to STDERR. Those will go to your error log.

    And, of course, you might have better luck asking the Bugzilla people themselves. They might have encountered this problem before. Do they have a mailing list or discussion board (or Bugzilla Bugzilla :) )?

      You're spot on, something else is causing it. In my experience, I found that the print "content-type: text/html\n\n"; script has to be my second line of the script, right after #!/usr/bin/perl, as I will mostly catch anything else after that.

      Run the perl script manually, and look at the output. See if anything obvious pops up. Secondly, change your code, and look at anything between the start of the script and where you have the print "content-type: piece.

      There are only so many things that can cause a CGI to crash. The most difficult ones, is when a script does something, it fails, and you don't do any error checking on that. That will keep you busy for a while, especially if you start dealing with DBI's, where you get database errors before you even print the display out.

        Thank you both for replying. I will try those suggestions to see if it helps. It may take a little while since I can't seem to re-create it at will, but I'll post back with my findings. Thanks again!