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 -- unsubscribe: yahns-public+unsubscr...@yhbt.net archive: https://yhbt.net/yahns-public/