yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Cc: Eric Wong <e@80x24.org>
Subject: [WIP] proxy_pass: experiment to disable buffer sharing
Date: Tue, 14 Apr 2015 21:31:40 +0000	[thread overview]
Message-ID: <20150414213140.GA6061@dcvr.yhbt.net> (raw)

I suspect we're inadvertantly sharing buffers somewhere and
leading to segfaults down-the-line.  The core dumps I've gotten
aren't even close to any of the new proxy code, so it looks like
the bug is due to mis-sharing of a thread-local buffer which
we didn't detached.

Will run this for a few days to see if there's still segfaults
with the proxy code.  Multithreading is tricky...

Not going to push this, but I'm fairly convinced the issue
somewhere related and can be fixed without thrashing allocations.
---
 lib/yahns/proxy_http_response.rb |  8 ++++----
 lib/yahns/proxy_pass.rb          | 12 ++----------
 2 files changed, 6 insertions(+), 14 deletions(-)

diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb
index af8d8cc..632dfe6 100644
--- a/lib/yahns/proxy_http_response.rb
+++ b/lib/yahns/proxy_http_response.rb
@@ -88,7 +88,7 @@ module Yahns::HttpResponse # :nodoc:
       break # keep buffering as much as possible
     end while true
 
-    rbuf = Thread.current[:yahns_rbuf]
+    rbuf = ''
     tip = tip.empty? ? [] : [ tip ]
 
     if have_body
@@ -123,7 +123,7 @@ module Yahns::HttpResponse # :nodoc:
 
         buf = tmp
         req_res.proxy_trailers = [ buf, tlr = [] ]
-        rbuf = Thread.current[:yahns_rbuf] = ''
+        rbuf = ''
         until kcar.trailers(tlr, buf)
           case rv = req_res.kgio_tryread(0x2000, rbuf)
           when String
@@ -165,7 +165,7 @@ module Yahns::HttpResponse # :nodoc:
   end
 
   def proxy_response_finish(kcar, wbuf, req_res)
-    rbuf = Thread.current[:yahns_rbuf]
+    rbuf = ''
     if len = kcar.body_bytes_left
 
       case tmp = req_res.kgio_tryread(0x2000, rbuf)
@@ -193,7 +193,7 @@ module Yahns::HttpResponse # :nodoc:
           return :wait_readable # self remains in :ignore, wait on upstream
         end until kcar.body_eof?
         req_res.proxy_trailers = [ tmp, [] ] # onto trailers!
-        rbuf = Thread.current[:yahns_rbuf] = ''
+        rbuf = ''
       end
 
       buf, tlr = *req_res.proxy_trailers
diff --git a/lib/yahns/proxy_pass.rb b/lib/yahns/proxy_pass.rb
index e86e9c9..f6021d4 100644
--- a/lib/yahns/proxy_pass.rb
+++ b/lib/yahns/proxy_pass.rb
@@ -21,17 +21,11 @@ class Yahns::ProxyPass # :nodoc:
       Thread.current[:yahns_queue].queue_add(self, Yahns::Queue::QEV_WR)
     end
 
-    # we must reinitialize the thread-local rbuf if it may get beyond the
-    # current thread
-    def detach_rbuf!
-      Thread.current[:yahns_rbuf] = ''
-    end
-
     def yahns_step # yahns event loop entry point
       c = @yahns_client
       case req = @rrstate
       when Kcar::Parser # reading response...
-        buf = Thread.current[:yahns_rbuf]
+        buf = ''
 
         case resbuf = @resbuf # where are we at the response?
         when nil # common case, catch the response header in a single read
@@ -41,8 +35,8 @@ class Yahns::ProxyPass # :nodoc:
             if res = req.headers(@hdr = [], rv)
               return c.proxy_response_start(res, rv, req, self)
             else # ugh, big headers or tricked response
-              buf = detach_rbuf!
               @resbuf = rv
+              buf = ''
             end
             # continue looping in middle "case @resbuf" loop
           when :wait_readable
@@ -109,7 +103,6 @@ class Yahns::ProxyPass # :nodoc:
           when Array
             vec = rv # partial write, retry in case loop
           when :wait_writable
-            detach_rbuf!
             req[0] = vec
             return :wait_writable
           when nil
@@ -128,7 +121,6 @@ class Yahns::ProxyPass # :nodoc:
           when String
             buf = rv # partial write, retry in case loop
           when :wait_writable
-            detach_rbuf!
             req[0] = buf
             return :wait_writable
           when nil
-- 
EW

             reply	other threads:[~2015-04-14 21:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-14 21:31 Eric Wong [this message]
2015-04-17  2:21 ` [WIP] proxy_pass: experiment to disable buffer sharing 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=20150414213140.GA6061@dcvr.yhbt.net \
    --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).