From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS30633 207.244.64.0/18 X-Spam-Status: No, score=-0.1 required=3.0 tests=AWL,BAYES_00, RCVD_IN_BL_SPAMCOP_NET,RCVD_IN_XBL,RDNS_NONE,SPF_FAIL,SPF_HELO_FAIL shortcircuit=no autolearn=no version=3.3.2 X-Original-To: yahns-public@yhbt.net Received: from 80x24.org (unknown [207.244.70.35]) by dcvr.yhbt.net (Postfix) with ESMTP id 6658063382B for ; Wed, 27 Apr 2016 00:27:20 +0000 (UTC) From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH 5/5] proxy_pass: drop resources immediately on errors Date: Wed, 27 Apr 2016 00:27:04 +0000 Message-Id: <20160427002704.10660-6-e@80x24.org> In-Reply-To: <20160427002704.10660-1-e@80x24.org> References: <20160427002704.10660-1-e@80x24.org> List-Id: We don't want to wait on GC to reap sockets on errors, generational GC in Ruby is less aggressive about reaping long-lived objects such as long-lived HTTP connections. --- lib/yahns/proxy_http_response.rb | 7 ++++++- lib/yahns/proxy_pass.rb | 5 +++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb index 3462e40..c5e7be5 100644 --- a/lib/yahns/proxy_http_response.rb +++ b/lib/yahns/proxy_http_response.rb @@ -43,7 +43,12 @@ def proxy_err_response(code, req_res, exc, wbuf) Rack::Utils::HTTP_STATUS_CODES[code]}\r\n\r\n") rescue nil shutdown rescue nil - req_res.shutdown rescue nil + @input = @input.close if @input + + # this is safe ONLY because we are in an :ignore state after + # Fdmap#forget when we got hijacked: + close + nil # signal close of req_res from yahns_step in yahns/proxy_pass.rb ensure wbuf.wbuf_abort if wbuf diff --git a/lib/yahns/proxy_pass.rb b/lib/yahns/proxy_pass.rb index 511db02..148957b 100644 --- a/lib/yahns/proxy_pass.rb +++ b/lib/yahns/proxy_pass.rb @@ -63,7 +63,8 @@ def yahns_step # yahns event loop entry point when Yahns::WbufCommon # streaming/buffering the response body - return c.proxy_response_finish(req, resbuf, self) + # we assign wbuf for rescue below: + return c.proxy_response_finish(req, wbuf = resbuf, self) end while true # case @resbuf @@ -79,7 +80,7 @@ def yahns_step # yahns event loop entry point when Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EPIPE e.set_backtrace([]) end - c.proxy_err_response(502, self, e, nil) + c.proxy_err_response(502, self, e, wbuf) end # returns :wait_readable if complete, :wait_writable if not -- EW