diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-11-06 23:12:08 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-11-07 00:29:23 +0000 |
commit | 950815b313a4e616c6fe39f46b2e894b51d7d62f (patch) | |
tree | 00d836e7c59a8b2df4f70d002953ed93ab0d77fc /extras | |
parent | 9dedbd699476bed21ee36e8eb479f838b25abffa (diff) | |
download | yahns-950815b313a4e616c6fe39f46b2e894b51d7d62f.tar.gz |
We don't want to leave extra resources lying around when slow clients read from us and yahns is forced to buffer. yahns delays the close of the request body until the request is fully written so response loggers can have an accurate time of how long it takes.
Diffstat (limited to 'extras')
-rw-r--r-- | extras/exec_cgi.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/extras/exec_cgi.rb b/extras/exec_cgi.rb index 170e773..c18c758 100644 --- a/extras/exec_cgi.rb +++ b/extras/exec_cgi.rb @@ -19,17 +19,24 @@ class ExecCgi end yield("0\r\n\r\n") if @chunked self + ensure + # do this sooner, since the response body may be buffered, we want + # to release our FD as soon as possible. + close end def close + # yahns will call this again after its done writing the response + # body, so we must ensure its idempotent. + # Note: this object (and any client-specific objects) will never + # be shared across different threads, so we do not need extra + # mutual exclusion here. + return if closed? super - if defined?(@my_pid) && @my_pid - begin - Process.waitpid(@my_pid) - rescue Errno::ECHILD - end - end - nil + begin + Process.waitpid(@my_pid) + rescue Errno::ECHILD + end if defined?(@my_pid) && @my_pid end end |