diff options
author | Eric Wong <e@80x24.org> | 2016-07-20 21:17:12 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-07-20 22:37:19 +0000 |
commit | 4335b6841d5aad1a57ee72b7476e1cec00cfb698 (patch) | |
tree | 5e83a8735fe3b7451a2e21125875d8c58d7c8c4b | |
parent | 98beb40e1fe27160ee1b3ac2c87ef3020426fd43 (diff) | |
download | yahns-4335b6841d5aad1a57ee72b7476e1cec00cfb698.tar.gz |
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
-rw-r--r-- | lib/yahns/wbuf_lite.rb | 13 |
1 files 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 @@ 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 |