Forum

Hiawatha, CGI and stdin timeout

Rodney Hester
25 April 2013, 16:46
Hiawatha version: 9.1
Operating System: Arch Linux on ARM

Using a pretty barebones Hiawatha configuration including the following (non-default) elements:

CGIextension = cgi
TimeForCGI = 30
ExecuteCGI = yes (as a Directory entry to the cgi-bin folder)

The following code snippet in a CGI target works on Apache, but hangs until timeout in Hiawatha (Hugo, I know how much you love to hear that :

#!/bin/bash
...
POST_DATA=$(</dev/stdin)
...


I've isolated the hang to that one line. I've verified that permissions aren't the issue (even setting the target of /dev/stdin to 777 didn't help), and I'm scratching my head to understand what the issue is. Google-fu didn't seem to help (or at least the two similar instances I found didn't seem related), I've scoured every post in the forum without a clear match, and there's nothing that stands out in the hiawatha.conf man page as a smoking gun.

Help?

Rodney
Hugo Leisink
25 April 2013, 17:00
Are you sure that reading from stdin only occurs when there actually is data to read? Try verifying that the environment variable REQUEST_METHOD is set to POST or CONTENT_LENGTH is set to a value greater than zero.
Rodney Hester
25 April 2013, 17:55
Good call - this allows the action=get query string to work properly (though if the pipe is empty, wouldn't it make more sense that POST_DATA would just be set to null in this case?). Unfortunately, action=put still times out when reading from /dev/stdin (and there is most definitely POST_DATA there in stdin). Here's the values on an actual put attempt via Hiawatha:

REQUEST_METHOD=POST
CONTENT_LENGTH=159

Same data via Apache, including POST_DATA (since it can be read):

REQUEST_METHOD=POST
CONTENT_LENGTH=159
POST_DATA:
name=a&title=b&comment=c&submit=Add+Comment&page=http%3A%2F%2Fmultics.minidns.net%2Fblog%2Farchives%2F2013%2F04%2F04%2Fa_not_so_brief_history_of_my_blogging%2F

Rodney
Hugo Leisink
25 April 2013, 18:54
It's probably because Hiawatha closes the handle which writes the request body to the stdin of the CGI application after the CGI has finished. Try reading CONTENT_LENGTH bytes instead of reading till the end of the stream, which is what '< /dev/stdin' does.
Rodney Hester
25 April 2013, 19:10
Nailed it. Changed:

POST_DATA=$(</dev/stdin)

to

read -n $CONTENT_LENGTH POST_DATA </dev/stdin

and it works like a charm (in both Hiawatha and Apache).

Thanks!

Rodney
This topic has been closed.