yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [ANN] yahns 1.13.0 -_- sleepy app server for Ruby
@ 2016-08-05  7:44  5% Eric Wong
  0 siblings, 0 replies; 4+ results
From: Eric Wong @ 2016-08-05  7:44 UTC (permalink / raw)
  To: ruby-talk; +Cc: yahns-public

A Free Software, multi-threaded, non-blocking network
application server designed for low _idle_ power consumption.
It is primarily optimized for applications with occasional users
which see little or no traffic.  yahns currently hosts Rack/HTTP
applications, but may eventually support other application
types.  Unlike some existing servers, yahns is extremely
sensitive to fatal bugs in the applications it hosts.

* git clone git://yhbt.net/yahns
* https://yahns.yhbt.net/README
* https://yahns.yhbt.net/NEWS.atom.xml
* we only accept plain-text email yahns-public@yhbt.net
* and archive all the mail we receive: https://yhbt.net/yahns-public/
* nntp://news.public-inbox.org/inbox.comp.lang.ruby.yahns

lrg nabgure ubeevoyl-anzrq freire :>

Changes:

    yahns 1.13.0 - some user-visible improvements...

    And probably a billion new regressions!

    yahns now allows users to skip the Rack::Head, Rack::Chunked and
    Rack::ContentLength middlewares to ease migrating from/to other
    real-world Rack HTTP servers.  Most notably, our chunked
    encoding implementation is a bit faster than Rack::Chunked by
    taking advantage of the writev(2) syscall:

      https://yhbt.net/yahns-public/20160803031906.14553-4-e@80x24.org/

    There's also rack 2.x fixes in the test case and extras/ section
    (these incompatibilities did not affect existing users unless
    they use the wonky extras/ section).

    There's also some graceful shutdown fixes, the process title is
    now changed to display the number of live FDs.

    Of course, there's the usual round of documentation improvements
    which are systemd and OpenSSL setup-related this time around.

    However, the majority of changes (proxy_*, wbuf_lite), affect
    currently-unadvertised functionality which is subject to removal
    or incompatible config changes.  However, they are used to serve
    our mailing list archives at:

            https://yhbt.net/yahns-public/

    49 changes since yahns 1.12.5:
          proxy_pass: simplify writing request bodies upstream
          proxy_pass: hoist out proxy_res_headers method
          proxy_pass: simplify proxy_http_response
          proxy_pass: split out body and trailer reading in response
          proxy_pass: trim down proxy_response_finish, too
          proxy_pass: split out req_res into a separate file
          proxy_pass: fix resumes after complete buffering is unblocked
          proxy_pass: X-Forwarded-For appends to existing list
          proxy_pass: pass entire object to proxy_http_response
          proxy_pass: support "proxy_buffering: false"
          proxy_pass: remove unnecessary rescue
          req_res: store proxy_pass object here, instead
          proxy_pass: redo "proxy_buffering: false"
          wbuf: remove needless "busy" parameter
          Merge branch 'maint'
          extras/try_gzip_static: do not show backtrace on syscall errors
          wbuf: remove tmpdir parameter
          wbuf_lite: fix write retries for OpenSSL sockets
          test_proxy_pass_no_buffering: fix racy test
          queue_*: check for closed IO objects
          cleanup graceful shutdown handling
          proxy_pass: more descriptive error messages
          proxy_pass: fix HTTP/1.0 backends on EOF w/o buffering
          wbuf_common: reset offset counter when done
          extras/try_gzip_static: resolve symlinks
          test_ssl: remove unnecessary priv_key DH parameter
          openssl_client: wrap shutdown for graceful termination
          proxy_pass: keep trailer buffer on blocked client writes
          proxy_pass: avoid TOCTTOU race when unbuffering, too
          proxy_pass: avoid accessing logger in env after hijacking
          proxy_pass: avoid stuck responses in "proxy_buffering: false"
          extras: include status messages in responses
          update init and add systemd examples
          test_proxy_pass_no_buffering: exclude rb/ru files, too
          wbuf_lite: use StringIO instead of TmpIO
          wbuf_lite: truncate StringIO when done
          wbuf_lite: prevent clobbering responses
          wbuf_lite: unify EOF error handling
          wbuf_lite: reset sf_offset/sf_count consistently
          wbuf_lite: clear @busy flag when re-arming
          http_response: drop bodies for non-compliant responses
          fix rack 2.x compatibility bugs
          doc: add session cache usage to OpenSSL example
          test: skip some buffering tests on non-default values
          response: drop clients after HTTP responses of unknown length
          response: reduce stack overhead for parameter passing
          response: support auto-chunking for HTTP/1.1
          Revert "document Rack::Chunked/ContentLength semi-requirements"
          extras/exec_cgi: fix for HTTPoxy vulnerability

Please note the disclaimer:

  yahns is extremely sensitive to fatal bugs in the apps it hosts.  There
  is no (and never will be) any built-in "watchdog"-type feature to kill
  stuck processes/threads.  Each yahns process may be handling thousands
  of clients; unexpectedly killing the process will abort _all_ of those
  connections.  Lives may be lost!

  yahns hackers are not responsible for your application/library bugs.
  Use an application server which is tolerant of buggy applications
  if you cannot be bothered to fix all your fatal bugs.
-- 
EW

^ permalink raw reply	[relevance 5%]

* [PATCH 7/7] proxy_pass: fix resumes after complete buffering is unblocked
  2016-05-16  1:43  6% [PATCH 0/7] proxy_pass cleanups Eric Wong
  2016-05-16  1:43  7% ` [PATCH 5/7] proxy_pass: trim down proxy_response_finish, too Eric Wong
@ 2016-05-16  1:43  4% ` Eric Wong
  1 sibling, 0 replies; 4+ results
From: Eric Wong @ 2016-05-16  1:43 UTC (permalink / raw)
  To: yahns-public

This fixes a bug where a cleared wbuf would kill the
process after the response got flushed out to the client
as `wbuf.busy' becomes `false'.

This fixes a regression introduced in
"proxy_pass: trim down proxy_response_finish, too"
which was never in a stable release
---
 lib/yahns/proxy_http_response.rb | 51 ++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb
index 65fd03b..284a3c6 100644
--- a/lib/yahns/proxy_http_response.rb
+++ b/lib/yahns/proxy_http_response.rb
@@ -160,7 +160,7 @@ def proxy_read_body(tip, kcar, req_res, alive, wbuf)
       req_res.proxy_trailers = [ rbuf.dup, tip ]
       return proxy_read_trailers(kcar, req_res, alive, wbuf)
     end
-    wbuf ? proxy_busy_mod_blocked(wbuf, wbuf.busy) : proxy_busy_mod_done(alive)
+    proxy_busy_mod(wbuf, alive)
   end
 
   def proxy_read_trailers(kcar, req_res, alive, wbuf)
@@ -178,7 +178,7 @@ def proxy_read_trailers(kcar, req_res, alive, wbuf)
       end # no loop here
     end
     wbuf = proxy_write(wbuf, trailer_out(tlr), alive)
-    wbuf ? proxy_busy_mod_blocked(wbuf, wbuf.busy) : proxy_busy_mod_done(alive)
+    proxy_busy_mod(wbuf, alive)
   end
 
   # start streaming the response once upstream is done sending headers to us.
@@ -196,7 +196,7 @@ def proxy_response_start(res, tip, kcar, req_res)
 
     # all done reading response from upstream, req_res will be discarded
     # when we return nil:
-    wbuf ? proxy_busy_mod_blocked(wbuf, wbuf.busy) : proxy_busy_mod_done(alive)
+    proxy_busy_mod(wbuf, alive)
   rescue => e
     proxy_err_response(502, req_res, e, wbuf)
   end
@@ -218,7 +218,7 @@ def proxy_wait_next(qflags)
     # <thread is scheduled away>                       | epoll_wait readiness
     #                                                  | ReqRes#yahns_step
     #                                                  | proxy dispatch ...
-    #                                                  | proxy_busy_mod_done
+    #                                                  | proxy_busy_mod
     # ************************** DANGER BELOW ********************************
     #                                                  | HttpClient#yahns_step
     #                                                  | # clears env
@@ -238,29 +238,28 @@ def proxy_wait_next(qflags)
     Thread.current[:yahns_queue].queue_mod(self, qflags)
   end
 
-  def proxy_busy_mod_done(alive)
-    case http_response_done(alive)
-    when :wait_readable then proxy_wait_next(Yahns::Queue::QEV_RD)
-    when :wait_writable then proxy_wait_next(Yahns::Queue::QEV_WR)
-    when :close then close
+  def proxy_busy_mod(wbuf, alive)
+    busy = wbuf.busy if wbuf
+    if busy
+      # we are completely done reading and buffering the upstream response,
+      # but have not completely written the response to the client,
+      # yield control to the client socket:
+      @state = wbuf
+      proxy_wait_next(case busy
+        when :wait_readable then Yahns::Queue::QEV_RD
+        when :wait_writable then Yahns::Queue::QEV_WR
+        else
+          raise "BUG: invalid wbuf.busy: #{busy.inspect}"
+        end)
+      # no touching self after proxy_wait_next, we may be running
+      # HttpClient#yahns_step in a different thread at this point
+    else
+      case http_response_done(alive)
+      when :wait_readable then proxy_wait_next(Yahns::Queue::QEV_RD)
+      when :wait_writable then proxy_wait_next(Yahns::Queue::QEV_WR)
+      when :close then close
+      end
     end
-
-    nil # signal close for ReqRes#yahns_step
-  end
-
-  def proxy_busy_mod_blocked(wbuf, busy)
-    # we are completely done reading and buffering the upstream response,
-    # but have not completely written the response to the client,
-    # yield control to the client socket:
-    @state = wbuf
-    proxy_wait_next(case busy
-      when :wait_readable then Yahns::Queue::QEV_RD
-      when :wait_writable then Yahns::Queue::QEV_WR
-      else
-        abort "BUG: invalid wbuf.busy: #{busy.inspect}"
-      end)
-    # no touching self after proxy_wait_next, we may be running
-    # HttpClient#yahns_step in a different thread at this point
     nil # signal close for ReqRes#yahns_step
   end
 

^ permalink raw reply related	[relevance 4%]

* [PATCH 5/7] proxy_pass: trim down proxy_response_finish, too
  2016-05-16  1:43  6% [PATCH 0/7] proxy_pass cleanups Eric Wong
@ 2016-05-16  1:43  7% ` Eric Wong
  2016-05-16  1:43  4% ` [PATCH 7/7] proxy_pass: fix resumes after complete buffering is unblocked Eric Wong
  1 sibling, 0 replies; 4+ results
From: Eric Wong @ 2016-05-16  1:43 UTC (permalink / raw)
  To: yahns-public

After the previous commits, we've added more branches
and made the existing response handling more generic;
so we can remove some duplicated logic and increase
review-ability.
---
 lib/yahns/proxy_http_response.rb | 66 ++--------------------------------------
 1 file changed, 3 insertions(+), 63 deletions(-)

diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb
index 52a8aff..65fd03b 100644
--- a/lib/yahns/proxy_http_response.rb
+++ b/lib/yahns/proxy_http_response.rb
@@ -202,69 +202,9 @@ def proxy_response_start(res, tip, kcar, req_res)
   end
 
   def proxy_response_finish(kcar, wbuf, req_res)
-    rbuf = Thread.current[:yahns_rbuf]
-    if len = kcar.body_bytes_left # known Content-Length
-
-      case tmp = req_res.kgio_tryread(0x2000, rbuf)
-      when String
-        len = kcar.body_bytes_left -= tmp.size
-        wbuf.wbuf_write(self, tmp)
-      when nil # premature EOF
-        return proxy_err_response(nil, req_res, nil, wbuf)
-      when :wait_readable
-        return :wait_readable # self remains in :ignore, wait on upstream
-      end while len != 0
-
-    elsif kcar.chunked? # nasty chunked response body
-      buf = ''.dup
-
-      unless req_res.proxy_trailers
-        # are we done dechunking the main body, yet?
-        case tmp = req_res.kgio_tryread(0x2000, rbuf)
-        when String
-          kcar.filter_body(buf, tmp)
-          buf.empty? or wbuf.wbuf_write(self, chunk_out(buf))
-        when nil # premature EOF
-          return proxy_err_response(nil, req_res, nil, wbuf)
-        when :wait_readable
-          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] = ''.dup
-      end
-
-      buf, tlr = *req_res.proxy_trailers
-      until kcar.trailers(tlr, buf)
-        case rv = req_res.kgio_tryread(0x2000, rbuf)
-        when String
-          buf << rv
-        when :wait_readable
-          return :wait_readable
-        when nil # premature EOF
-          return proxy_err_response(nil, req_res, nil, wbuf)
-        end # no loop here
-      end
-      wbuf.wbuf_write(self, trailer_out(tlr))
-
-    else # no Content-Length or Transfer-Encoding: chunked, wait on EOF!
-
-      alive = wbuf.wbuf_persist
-      case tmp = req_res.kgio_tryread(0x2000, rbuf)
-      when String
-        tmp = chunk_out(tmp) if alive
-        wbuf.wbuf_write(self, tmp)
-      when nil
-        wbuf.wbuf_write(self, "0\r\n\r\n".freeze) if alive
-        req_res.shutdown
-        break
-      when :wait_readable
-        return :wait_readable # self remains in :ignore, wait on upstream
-      end while true
-
-    end
-
-    busy = wbuf.busy and return proxy_busy_mod_blocked(wbuf, busy)
-    proxy_busy_mod_done(wbuf.wbuf_persist) # returns nil to close req_res
+    alive = wbuf.wbuf_persist
+    req_res.proxy_trailers ? proxy_read_trailers(kcar, req_res, alive, wbuf)
+                           : proxy_read_body([], kcar, req_res, alive, wbuf)
   end
 
   def proxy_wait_next(qflags)

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/7] proxy_pass cleanups
@ 2016-05-16  1:43  6% Eric Wong
  2016-05-16  1:43  7% ` [PATCH 5/7] proxy_pass: trim down proxy_response_finish, too Eric Wong
  2016-05-16  1:43  4% ` [PATCH 7/7] proxy_pass: fix resumes after complete buffering is unblocked Eric Wong
  0 siblings, 2 replies; 4+ results
From: Eric Wong @ 2016-05-16  1:43 UTC (permalink / raw)
  To: yahns-public

A bunch of cleanups to hopefully make the proxy_pass-related
code a little saner and easier-to-follow.

I introduced at least one bug during this series which got fixed
in 7/7.

Extra sets of eyes to review would be greatly appreciated, thanks!

And this is running live and serving critical information to
readers of https://yhbt.net/ in all its glory!

Once I'm reasonably satisfied with this; I'll continue work
on making "proxy_buffering: false" work, so slow-client-capable
upstreams can generate gigantic (hundreds of megabytes!)
responses without filesystem overhead.

But first, I think I should work on making those gigantic
responses cheaper in terms of memory/CPU usage outside of
yahns.  This is git-http-backend for serving mega repos
over smart HTTP, yahns is already great for dumb HTTP
git clones.

 lib/yahns/proxy_http_response.rb | 236 +++++++++++++++------------------------
 lib/yahns/proxy_pass.rb          | 171 +---------------------------
 lib/yahns/req_res.rb             | 159 ++++++++++++++++++++++++++
 3 files changed, 252 insertions(+), 314 deletions(-)

Eric Wong (7):
      proxy_pass: simplify writing request bodies upstream
      proxy_pass: hoist out proxy_res_headers method
      proxy_pass: simplify proxy_http_response
      proxy_pass: split out body and trailer reading in response
      proxy_pass: trim down proxy_response_finish, too
      proxy_pass: split out req_res into a separate file
      proxy_pass: fix resumes after complete buffering is unblocked

^ permalink raw reply	[relevance 6%]

Results 1-4 of 4 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2016-05-16  1:43  6% [PATCH 0/7] proxy_pass cleanups Eric Wong
2016-05-16  1:43  7% ` [PATCH 5/7] proxy_pass: trim down proxy_response_finish, too Eric Wong
2016-05-16  1:43  4% ` [PATCH 7/7] proxy_pass: fix resumes after complete buffering is unblocked Eric Wong
2016-08-05  7:44  5% [ANN] yahns 1.13.0 -_- sleepy app server for Ruby Eric Wong

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