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 1/2] wbuf_lite: prevent clobbering responses
Date: Tue, 19 Jul 2016 22:24:36 +0000	[thread overview]
Message-ID: <20160719222437.23103-2-e@80x24.org> (raw)
In-Reply-To: <20160719222437.23103-1-e@80x24.org>

All of our wbuf code assumes we append to existing buffers
(files) since sendfile cannot deal otherwise.  We also
follow this pattern for StringIO to avoid extra data copies.
---
 lib/yahns/wbuf.rb      | 1 +
 lib/yahns/wbuf_lite.rb | 7 ++++---
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/lib/yahns/wbuf.rb b/lib/yahns/wbuf.rb
index 583df10..3abc5f9 100644
--- a/lib/yahns/wbuf.rb
+++ b/lib/yahns/wbuf.rb
@@ -58,6 +58,7 @@ def wbuf_write(c, buf)
     end until @busy
 
     @tmpio ||= Yahns::TmpIO.new(c.class.output_buffer_tmpdir)
+    # n.b.: we rely on O_APPEND in TmpIO, here
     @sf_count += String === buf ? @tmpio.write(buf) : wbuf_writev(buf)
 
     # we spent some time copying to the FS, try to write to
diff --git a/lib/yahns/wbuf_lite.rb b/lib/yahns/wbuf_lite.rb
index 1902ce7..8a93ad1 100644
--- a/lib/yahns/wbuf_lite.rb
+++ b/lib/yahns/wbuf_lite.rb
@@ -33,6 +33,7 @@ def wbuf_write(c, buf)
     end until @busy
 
     @tmpio ||= StringIO.new(''.dup) # relies on encoding: binary above
+    @tmpio.seek(0, 2) # fake O_APPEND behavior
     @sf_count += @tmpio.write(buf)
 
     # we spent some time copying to the FS, try to write to
@@ -45,12 +46,12 @@ def wbuf_write(c, buf)
       @busy = rv
       return rv
     else
-      raise "BUG: #{rv.nil? ? "EOF" : rv.inspect} on tmpio " \
+      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 prevent dirty data from getting flushed
-    # to disk if we can help it.
+    # we're all caught up, try to save some memory if we can help it.
     wbuf_abort
     @sf_offset = 0
     @busy = false
-- 
EW


  reply	other threads:[~2016-07-19 22:24 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 ` Eric Wong [this message]
2016-07-19 22:24 ` [PATCH 2/2] wbuf_lite: unify EOF error handling Eric Wong
2016-07-20 22:40 ` [PATCH 3/2] wbuf_lite: reset sf_offset/sf_count consistently Eric Wong
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=20160719222437.23103-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=yahns-public@yhbt.net \
    --subject='Re: [PATCH 1/2] wbuf_lite: prevent clobbering responses' \
    /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

Code repositories for project(s) associated with this inbox:

	../../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).