diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-11-06 17:59:25 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-11-06 18:52:55 +0000 |
commit | a32d80a93101b884c44991247b8278002368d483 (patch) | |
tree | e7c8ceedffccbf33d023d9a6f7267886072e66ee /lib/yahns/http_response.rb | |
parent | 52f2a4055a0f7e27df02d40bb42dda446dcdf89d (diff) | |
download | yahns-a32d80a93101b884c44991247b8278002368d483.tar.gz |
We can use the wbuf_close return value instead to ensure we close tmpio properly and follow the same code path as a normal (:wait_writable-triggering) buffered response would. Add a few tests to ensure we properly close the response body for exec_cgi, where I noticed zombies and started me down this rabbit hole looking for places where the response body was not closed properly.
Diffstat (limited to 'lib/yahns/http_response.rb')
-rw-r--r-- | lib/yahns/http_response.rb | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb index a520216..8a2426b 100644 --- a/lib/yahns/http_response.rb +++ b/lib/yahns/http_response.rb @@ -50,24 +50,20 @@ module Yahns::HttpResponse # :nodoc: wbuf = Yahns::Wbuf.new(body, alive, self.class.output_buffer_tmpdir) rv = wbuf.wbuf_write(self, header) body.each { |chunk| rv = wbuf.wbuf_write(self, chunk) } if body - wbuf_maybe(wbuf, rv, alive) + wbuf_maybe(wbuf, rv) end - def wbuf_maybe(wbuf, rv, alive) + def wbuf_maybe(wbuf, rv) case rv # wbuf_write return value when nil # all done - begin - case alive - when :ignore # hijacked - @state = alive - when Yahns::StreamFile - @state = alive - :wait_writable - when true, false - http_response_done(alive) - end - ensure - wbuf.wbuf_close(self) + case rv = wbuf.wbuf_close(self) + when :ignore # hijacked + @state = rv + when Yahns::StreamFile + @state = rv + :wait_writable + when true, false + http_response_done(rv) end else @state = wbuf @@ -188,7 +184,7 @@ module Yahns::HttpResponse # :nodoc: # (or :wait_readable for SSL) and hit Yahns::HttpClient#step_write if wbuf body = nil # ensure we do not close the body in ensure - wbuf_maybe(wbuf, rv, alive) + wbuf_maybe(wbuf, rv) else http_response_done(alive) end |