From 4335b6841d5aad1a57ee72b7476e1cec00cfb698 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 20 Jul 2016 21:17:12 +0000 Subject: wbuf_lite: reset sf_offset/sf_count consistently 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(-) (limited to 'lib') 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 @@ class Yahns::WbufLite # :nodoc: @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 @@ class Yahns::WbufLite # :nodoc: 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 @@ class Yahns::WbufLite # :nodoc: # 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 @@ class Yahns::WbufLite # :nodoc: 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 -- cgit v1.2.3-24-ge0c7