From 616e42c8d609905d9355bb5db726a5348303ffae Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 7 Jun 2016 04:07:20 +0000 Subject: proxy_pass: fix HTTP/1.0 backends on EOF w/o buffering We must ensure we properly close connections to HTTP/1.0 backends even if we blocked writing on outgoing data. --- lib/yahns/proxy_http_response.rb | 9 +++++---- lib/yahns/wbuf_lite.rb | 7 +++++-- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb index 9867da2..316c310 100644 --- a/lib/yahns/proxy_http_response.rb +++ b/lib/yahns/proxy_http_response.rb @@ -10,13 +10,14 @@ require_relative 'wbuf_lite' module Yahns::HttpResponse # :nodoc: # switch and yield - def proxy_unbuffer(wbuf) + def proxy_unbuffer(wbuf, nxt = :ignore) @state = wbuf + wbuf.req_res = nil if nxt.nil? && wbuf.respond_to?(:req_res=) tc = Thread.current tc[:yahns_fdmap].remember(self) # Yahns::HttpClient tc[:yahns_queue].queue_mod(self, wbuf.busy == :wait_readable ? Yahns::Queue::QEV_RD : Yahns::Queue::QEV_WR) - :ignore + nxt end def wbuf_alloc(req_res) @@ -175,9 +176,9 @@ module Yahns::HttpResponse # :nodoc: # HTTP/1.0 upstream: wbuf = proxy_write(wbuf, "0\r\n\r\n".freeze, req_res) if alive - return proxy_unbuffer(wbuf) if Yahns::WbufLite === wbuf req_res.shutdown - break + return proxy_unbuffer(wbuf, nil) if Yahns::WbufLite === wbuf + return proxy_busy_mod(wbuf, req_res) when :wait_readable return wait_on_upstream(req_res) end until kcar.body_eof? diff --git a/lib/yahns/wbuf_lite.rb b/lib/yahns/wbuf_lite.rb index afee1e9..fa52f54 100644 --- a/lib/yahns/wbuf_lite.rb +++ b/lib/yahns/wbuf_lite.rb @@ -7,9 +7,11 @@ require_relative 'wbuf' # This is only used for "proxy_buffering: false" class Yahns::WbufLite < Yahns::Wbuf # :nodoc: attr_reader :busy + attr_writer :req_res def initialize(req_res) - super(nil, :ignore) + alive = req_res.alive + super(nil, alive ? :ignore : false) @req_res = req_res end @@ -35,8 +37,9 @@ class Yahns::WbufLite < Yahns::Wbuf # :nodoc: if @req_res client.hijack_cleanup Thread.current[:yahns_queue].queue_mod(@req_res, Yahns::Queue::QEV_RD) + return :ignore end - :ignore + @wbuf_persist rescue @req_res = @req_res.close if @req_res raise -- cgit v1.2.3-24-ge0c7