yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH 3/2] wbuf_lite: reset sf_offset/sf_count consistently
Date: Wed, 20 Jul 2016 22:40:49 +0000	[thread overview]
Message-ID: <20160720224049.GA13541@dcvr> (raw)
In-Reply-To: <20160719222437.23103-1-e@80x24.org>

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

  parent reply	other threads:[~2016-07-20 22:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-19 22:24 [PATCH] ANOTHER round of proxy_pass fixes Eric Wong
2016-07-19 22:24 ` [PATCH 1/2] wbuf_lite: prevent clobbering responses Eric Wong
2016-07-19 22:24 ` [PATCH 2/2] wbuf_lite: unify EOF error handling Eric Wong
2016-07-20 22:40 ` Eric Wong [this message]
2016-07-21  0:57 ` [PATCH 4/2] wbuf_lite: clear @busy flag when re-arming Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/yahns/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160720224049.GA13541@dcvr \
    --to=e@80x24.org \
    --cc=yahns-public@yhbt.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/yahns.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).