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 via email to