Forum

Time out in previously working CGI script

Sabu Francis
25 February 2012, 18:41
Hiawatha version: 8.01
Operating System: Ubuntu

Hi
I have a website that was working just fine in Apache, which I have now migrated to Hiawatha. I am quite happy with the migration excepting for one CGI Script which is consistently timing out irrespective of setting a high time for 'TimeForCGI' in that particular virtual host

These are the details:
a) This CGI script is written in Rebol language and it works perfectly fine in Apache. The CGI script is invoked by the usual !# command at the beginning of the script. Other scripts are working fine
b) This CGI script first creates an HTML which does get displayed in the browser. Then a javascript function in that displayed HTML file in the browser invokes the same CGI script again via Ajax (with different QUERY_STRING parameters). For this I use JQuery.ajaxSubmit() That does the final step of adding some more detail into the displayed HTML

I am preplexed why is that this particular CGI script was working just fine in Apache, and here it is giving so much problem. I tried several TimeForCGI and now the setting is 125 seconds (It really does not need all that much) I also know that Rebol does not have a Timeout value or stops the execution of the script. If I manually call the script with the QUERY_STRING parameters used by the Ajax, it works just fine. It is just in the Ajax call, (i.e. the call made internally by the browser) that it timesout and I saw that entry in the error.log file

Any help would be appreciated.

Thanks for a good product
Regards
Sabu Francis
Sabu Francis
25 February 2012, 18:47
Ok. I got the previous script to work.

Firstly a correction: The AjaxSubmit() was doing a 'POST' invocation of a form in the previously created HTML.

I changed that 'POST' to a 'GET' and now it is working

In short, I seriously think Hiawatha is having some problem with timeout when we use Ajax POST. The GET method seems to be working. Maybe you should look into that

Thanks again
Hugo Leisink
25 February 2012, 18:56
I can assure that Hiawatha works fine. A POST request via AJAX is no different from a 'normal' POST request. The only extra in a AJAX POST requests is the "X-Requested-With: XMLHttpRequest" HTTP header line.

Most of the time, timeouts occur when a CGI script prints an incorrect Content-Length line. If a script writes "Content-Length: 10", but only writes 5 bytes of HTTP content, the browser waits for the final 5 byte. If they are never written, you'll get a timeout error.

What I advice you to do is to install Fiddler2 [fiddler2.com] to see what goes wrong.
Sabu Francis
25 February 2012, 22:27
Hi
Thanks for responding fast. Is 'Content-Length' mandatory? I did not send any 'Content-length:' string in my header of my CGI Post when I was posting it via my Apache server. There it worked fine. I had just sent 'Content-type: text/html\n\n"

Maybe Hiawatha is stringent about 'Content-Length' ? What happens if it is not sent at all? Will it still be waiting?

Thanks

Regards
Sabu Francis
Hugo Leisink
26 February 2012, 08:52
The Content-Length is an optional header. But if a CGI script does print it, it should be correct.

If it is not printed, Hiawatha will continue to read until the end of the stream.

In my previous post, I made a mistake. It's of course not Hiawatha waiting for the final 5 bytes, it's the browser who's waiting for the last bytes.
This topic has been closed.