From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 07E0E2034E; Wed, 20 Jul 2016 22:40:50 +0000 (UTC) Date: Wed, 20 Jul 2016 22:40:49 +0000 From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH 3/2] wbuf_lite: reset sf_offset/sf_count consistently Message-ID: <20160720224049.GA13541@dcvr> References: <20160719222437.23103-1-e@80x24.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160719222437.23103-1-e@80x24.org> List-Id: Since we use wbuf_lite for long, streaming requests, we need to reset the offset and counts when aborting the existing wbuf and not assume the wbuf goes out-of-scope and expires when we are done using it. Fix stupid bugs in BUG notices while we're at it :x --- lib/yahns/wbuf_lite.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/yahns/wbuf_lite.rb b/lib/yahns/wbuf_lite.rb index 577b4dc..7d77da9 100644 --- a/lib/yahns/wbuf_lite.rb +++ b/lib/yahns/wbuf_lite.rb @@ -46,14 +46,13 @@ def wbuf_write(c, buf) @busy = rv return rv else - raise "BUG: #{rv.nil? ? 'EOF' : rv.inspect} on " + raise "BUG: #{rv.nil? ? 'EOF' : rv.inspect} on " \ "tmpio.size=#{@tmpio.size} " \ "sf_offset=#@sf_offset sf_count=#@sf_count" end while @sf_count > 0 # we're all caught up, try to save some memory if we can help it. wbuf_abort - @sf_offset = 0 @busy = false nil rescue @@ -69,7 +68,7 @@ def wbuf_flush(client) when :wait_writable, :wait_readable return rv else - raise "BUG: #{rv.nil? ? 'EOF' : rv.inspect} on " + raise "BUG: #{rv.nil? ? 'EOF' : rv.inspect} on " \ "tmpio.size=#{@tmpio.size} " \ "sf_offset=#@sf_offset sf_count=#@sf_count" end while @sf_count > 0 @@ -83,7 +82,7 @@ def wbuf_flush(client) # called by Yahns::HttpClient#step_write def wbuf_close(client) - wbuf_abort + wbuf_abort if @tmpio # resume the event loop when @blocked is empty # The actual Yahns::ReqRes#yahns_step is actually read/write-event @@ -102,12 +101,10 @@ def wbuf_close(client) end def wbuf_abort + @sf_offset = @sf_count = 0 # we can safely truncate since this is a StringIO, we cannot do this # with a real file because zero-copy with sendfile means truncating # a while could clobber in-flight data - if @tmpio - @tmpio.truncate(0) - @tmpio = @tmpio.close - end + @tmpio.truncate(0) end end -- EW