diff options
author | Eric Wong <e@80x24.org> | 2016-05-15 07:55:40 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-05-16 01:13:01 +0000 |
commit | c1f04188bc08d6e2de39dd4f7cba90dd5be2a227 (patch) | |
tree | 288ee287fa5920a9768a1bb74f801ffc8f552772 | |
parent | e2be32ddfccd1958dcfbb8ab15057ab31fda7b7b (diff) | |
download | yahns-c1f04188bc08d6e2de39dd4f7cba90dd5be2a227.tar.gz |
This fixes a bug where a cleared wbuf would kill the process after the response got flushed out to the client as `wbuf.busy' becomes `false'. This fixes a regression introduced in "proxy_pass: trim down proxy_response_finish, too" which was never in a stable release
-rw-r--r-- | lib/yahns/proxy_http_response.rb | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb index 65fd03b..284a3c6 100644 --- a/lib/yahns/proxy_http_response.rb +++ b/lib/yahns/proxy_http_response.rb @@ -160,7 +160,7 @@ module Yahns::HttpResponse # :nodoc: req_res.proxy_trailers = [ rbuf.dup, tip ] return proxy_read_trailers(kcar, req_res, alive, wbuf) end - wbuf ? proxy_busy_mod_blocked(wbuf, wbuf.busy) : proxy_busy_mod_done(alive) + proxy_busy_mod(wbuf, alive) end def proxy_read_trailers(kcar, req_res, alive, wbuf) @@ -178,7 +178,7 @@ module Yahns::HttpResponse # :nodoc: end # no loop here end wbuf = proxy_write(wbuf, trailer_out(tlr), alive) - wbuf ? proxy_busy_mod_blocked(wbuf, wbuf.busy) : proxy_busy_mod_done(alive) + proxy_busy_mod(wbuf, alive) end # start streaming the response once upstream is done sending headers to us. @@ -196,7 +196,7 @@ module Yahns::HttpResponse # :nodoc: # all done reading response from upstream, req_res will be discarded # when we return nil: - wbuf ? proxy_busy_mod_blocked(wbuf, wbuf.busy) : proxy_busy_mod_done(alive) + proxy_busy_mod(wbuf, alive) rescue => e proxy_err_response(502, req_res, e, wbuf) end @@ -218,7 +218,7 @@ module Yahns::HttpResponse # :nodoc: # <thread is scheduled away> | epoll_wait readiness # | ReqRes#yahns_step # | proxy dispatch ... - # | proxy_busy_mod_done + # | proxy_busy_mod # ************************** DANGER BELOW ******************************** # | HttpClient#yahns_step # | # clears env @@ -238,29 +238,28 @@ module Yahns::HttpResponse # :nodoc: Thread.current[:yahns_queue].queue_mod(self, qflags) end - def proxy_busy_mod_done(alive) - case http_response_done(alive) - when :wait_readable then proxy_wait_next(Yahns::Queue::QEV_RD) - when :wait_writable then proxy_wait_next(Yahns::Queue::QEV_WR) - when :close then close + def proxy_busy_mod(wbuf, alive) + busy = wbuf.busy if wbuf + if busy + # we are completely done reading and buffering the upstream response, + # but have not completely written the response to the client, + # yield control to the client socket: + @state = wbuf + proxy_wait_next(case busy + when :wait_readable then Yahns::Queue::QEV_RD + when :wait_writable then Yahns::Queue::QEV_WR + else + raise "BUG: invalid wbuf.busy: #{busy.inspect}" + end) + # no touching self after proxy_wait_next, we may be running + # HttpClient#yahns_step in a different thread at this point + else + case http_response_done(alive) + when :wait_readable then proxy_wait_next(Yahns::Queue::QEV_RD) + when :wait_writable then proxy_wait_next(Yahns::Queue::QEV_WR) + when :close then close + end end - - nil # signal close for ReqRes#yahns_step - end - - def proxy_busy_mod_blocked(wbuf, busy) - # we are completely done reading and buffering the upstream response, - # but have not completely written the response to the client, - # yield control to the client socket: - @state = wbuf - proxy_wait_next(case busy - when :wait_readable then Yahns::Queue::QEV_RD - when :wait_writable then Yahns::Queue::QEV_WR - else - abort "BUG: invalid wbuf.busy: #{busy.inspect}" - end) - # no touching self after proxy_wait_next, we may be running - # HttpClient#yahns_step in a different thread at this point nil # signal close for ReqRes#yahns_step end |