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  6% 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 6%]

* [PATCH] wbuf_common: reset offset counter when done
@ 2016-06-14 19:41  7% Eric Wong
  0 siblings, 0 replies; 4+ results
From: Eric Wong @ 2016-06-14 19:41 UTC (permalink / raw)
  To: yahns-public

This fixes a case where "proxy_buffering: false" users may
encounter a "upstream error: BUG: EOF on tmpio sf_offset="
as a wbuf may be reused.

Oddly, it took over one week of running the latest proxy_pass
as of commit 616e42c8d609905d9355bb5db726a5348303ffae
("proxy_pass: fix HTTP/1.0 backends on EOF w/o buffering")
---
 lib/yahns/wbuf_common.rb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/yahns/wbuf_common.rb b/lib/yahns/wbuf_common.rb
index cded2e3..2799baf 100644
--- a/lib/yahns/wbuf_common.rb
+++ b/lib/yahns/wbuf_common.rb
@@ -19,7 +19,10 @@ module Yahns::WbufCommon # :nodoc:
   def wbuf_flush(client)
     case rv = client.trysendfile(@tmpio, @sf_offset, @sf_count)
     when Integer
-      return wbuf_close(client) if (@sf_count -= rv) == 0 # all sent!
+      if (@sf_count -= rv) == 0 # all sent!
+        @sf_offset = 0
+        return wbuf_close(client)
+      end
 
       @sf_offset += rv # keep going otherwise
     when :wait_writable, :wait_readable

^ permalink raw reply related	[relevance 7%]

* [PATCH 5/5] proxy_pass: fix HTTP/1.0 backends on EOF w/o buffering
  2016-06-07  7:39  6% [PATCH \0/5] another round of proxy-related bugfixes! Eric Wong
@ 2016-06-07  7:39  5% ` Eric Wong
  0 siblings, 0 replies; 4+ results
From: Eric Wong @ 2016-06-07  7:39 UTC (permalink / raw)
  To: yahns-public

We must ensure we properly close connections to HTTP/1.0
backends even if we blocked writing on outgoing data.
---
 lib/yahns/proxy_http_response.rb     |   9 ++-
 lib/yahns/wbuf_lite.rb               |   7 +-
 test/test_proxy_pass_no_buffering.rb | 138 +++++++++++++++++++----------------
 3 files changed, 84 insertions(+), 70 deletions(-)

diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb
index 9867da2..316c310 100644
--- a/lib/yahns/proxy_http_response.rb
+++ b/lib/yahns/proxy_http_response.rb
@@ -10,13 +10,14 @@
 module Yahns::HttpResponse # :nodoc:
 
   # switch and yield
-  def proxy_unbuffer(wbuf)
+  def proxy_unbuffer(wbuf, nxt = :ignore)
     @state = wbuf
+    wbuf.req_res = nil if nxt.nil? && wbuf.respond_to?(:req_res=)
     tc = Thread.current
     tc[:yahns_fdmap].remember(self) # Yahns::HttpClient
     tc[:yahns_queue].queue_mod(self, wbuf.busy == :wait_readable ?
                                Yahns::Queue::QEV_RD : Yahns::Queue::QEV_WR)
-    :ignore
+    nxt
   end
 
   def wbuf_alloc(req_res)
@@ -175,9 +176,9 @@ def proxy_read_body(tip, kcar, req_res)
 
       # HTTP/1.0 upstream:
       wbuf = proxy_write(wbuf, "0\r\n\r\n".freeze, req_res) if alive
-      return proxy_unbuffer(wbuf) if Yahns::WbufLite === wbuf
       req_res.shutdown
-      break
+      return proxy_unbuffer(wbuf, nil) if Yahns::WbufLite === wbuf
+      return proxy_busy_mod(wbuf, req_res)
     when :wait_readable
       return wait_on_upstream(req_res)
     end until kcar.body_eof?
diff --git a/lib/yahns/wbuf_lite.rb b/lib/yahns/wbuf_lite.rb
index afee1e9..fa52f54 100644
--- a/lib/yahns/wbuf_lite.rb
+++ b/lib/yahns/wbuf_lite.rb
@@ -7,9 +7,11 @@
 # This is only used for "proxy_buffering: false"
 class Yahns::WbufLite < Yahns::Wbuf # :nodoc:
   attr_reader :busy
+  attr_writer :req_res
 
   def initialize(req_res)
-    super(nil, :ignore)
+    alive = req_res.alive
+    super(nil, alive ? :ignore : false)
     @req_res = req_res
   end
 
@@ -35,8 +37,9 @@ def wbuf_close(client)
     if @req_res
       client.hijack_cleanup
       Thread.current[:yahns_queue].queue_mod(@req_res, Yahns::Queue::QEV_RD)
+      return :ignore
     end
-    :ignore
+    @wbuf_persist
   rescue
     @req_res = @req_res.close if @req_res
     raise
diff --git a/test/test_proxy_pass_no_buffering.rb b/test/test_proxy_pass_no_buffering.rb
index c60ccad..0afa4e1 100644
--- a/test/test_proxy_pass_no_buffering.rb
+++ b/test/test_proxy_pass_no_buffering.rb
@@ -18,8 +18,13 @@ def call(env)
       when 'GET'
         case env['PATH_INFO']
         when '/giant-body'
-          h = [ %W(content-type text/pain),
-                   %W(content-length #{NCHUNK * STR4.size}) ]
+          h = [ %W(content-type text/pain) ]
+
+          # HTTP/1.0 is not Rack-compliant, so no Rack::Lint for us :)
+          if env['HTTP_VERSION'] == 'HTTP/1.1'
+            h << %W(content-length #{NCHUNK * STR4.size})
+          end
+
           body = Object.new
           def body.each
             NCHUNK.times { yield STR4 }
@@ -53,6 +58,7 @@ def check_headers(io)
   end
 
   def test_proxy_pass_no_buffering
+    to_close = []
     err, cfg, host, port = @err, Yahns::Config.new, @srv.addr[3], @srv.addr[1]
     host2, port2 = @srv2.addr[3], @srv2.addr[1]
     pxp = Yahns::ProxyPass.new("http://#{host2}:#{port2}",
@@ -81,79 +87,83 @@ def test_proxy_pass_no_buffering
         stderr_path err.path
       end
     end
-    s = TCPSocket.new(host, port)
-    req = "GET /giant-body HTTP/1.1\r\nHost: example.com\r\n" \
-          "Connection: close\r\n\r\n"
-    s.write(req)
-    bufs = []
-    sleep 1
-    10.times do
-      sleep 0.1
-      # ensure no files get created
-      if RUBY_PLATFORM =~ /\blinux\b/ && `which lsof 2>/dev/null`.size >= 4
-        qtmpdir = Regexp.quote("#@tmpdir/")
-        deleted1 = `lsof -p #{pid}`.split("\n")
-        deleted1 = deleted1.grep(/\bREG\b.*#{qtmpdir}.* \(deleted\)/)
-        deleted2 = `lsof -p #{pid2}`.split("\n")
-        deleted2 = deleted2.grep(/\bREG\b.*#{qtmpdir}.* \(deleted\)/)
-        [ deleted1, deleted2 ].each do |ary|
-          ary.delete_if { |x| x =~ /\.(?:err|out) \(deleted\)/ }
+    %w(1.0 1.1).each do |ver|
+      s = TCPSocket.new(host, port)
+      to_close << s
+      req = "GET /giant-body HTTP/#{ver}\r\nHost: example.com\r\n".dup
+      req << "Connection: close\r\n" if ver == '1.1'
+      req << "\r\n"
+      s.write(req)
+      bufs = []
+      sleep 1
+      10.times do
+        sleep 0.1
+        # ensure no files get created
+        if RUBY_PLATFORM =~ /\blinux\b/ && `which lsof 2>/dev/null`.size >= 4
+          qtmpdir = Regexp.quote("#@tmpdir/")
+          deleted1 = `lsof -p #{pid}`.split("\n")
+          deleted1 = deleted1.grep(/\bREG\b.*#{qtmpdir}.* \(deleted\)/)
+          deleted2 = `lsof -p #{pid2}`.split("\n")
+          deleted2 = deleted2.grep(/\bREG\b.*#{qtmpdir}.* \(deleted\)/)
+          [ deleted1, deleted2 ].each do |ary|
+            ary.delete_if { |x| x =~ /\.(?:err|out) \(deleted\)/ }
+          end
+          assert_equal 1, deleted1.size, "pid1=#{deleted1.inspect}"
+          assert_equal 0, deleted2.size, "pid2=#{deleted2.inspect}"
+          bufs.push(deleted1[0])
         end
-        assert_equal 1, deleted1.size, "pid1=#{deleted1.inspect}"
-        assert_equal 0, deleted2.size, "pid2=#{deleted2.inspect}"
-        bufs.push(deleted1[0])
       end
-    end
-    before = bufs.size
-    bufs.uniq!
-    assert bufs.size < before, 'unlinked buffer should not grow'
-    buf = ''.dup
-    slow = Digest::MD5.new
-    ft = Thread.new do
+      before = bufs.size
+      bufs.uniq!
+      assert bufs.size < before, 'unlinked buffer should not grow'
+      buf = ''.dup
+      slow = Digest::MD5.new
+      ft = Thread.new do
+        fast = Digest::MD5.new
+        f = TCPSocket.new(host2, port2)
+        f.write(req)
+        b2 = ''.dup
+        check_headers(f)
+        nf = 0
+        begin
+          f.readpartial(1024 * 1024, b2)
+          nf += b2.bytesize
+          fast.update(b2)
+        rescue EOFError
+          f = f.close
+        end while f
+        b2.clear
+        [ nf, fast.hexdigest ]
+      end
+      Thread.abort_on_exception = true
+      check_headers(s)
+      n = 0
+      begin
+        s.readpartial(1024 * 1024, buf)
+        slow.update(buf)
+        n += buf.bytesize
+        sleep 0.01
+      rescue EOFError
+        s = s.close
+      end while s
+      ft.join(5)
+      assert_equal [n, slow.hexdigest ], ft.value
+
       fast = Digest::MD5.new
-      f = TCPSocket.new(host2, port2)
+      f = TCPSocket.new(host, port)
       f.write(req)
-      b2 = ''.dup
       check_headers(f)
-      nf = 0
       begin
-        f.readpartial(1024 * 1024, b2)
-        nf += b2.bytesize
-        fast.update(b2)
+        f.readpartial(1024 * 1024, buf)
+        fast.update(buf)
       rescue EOFError
         f = f.close
       end while f
-      b2.clear
-      [ nf, fast.hexdigest ]
+      buf.clear
+      assert_equal slow.hexdigest, fast.hexdigest
     end
-    Thread.abort_on_exception = true
-    check_headers(s)
-    n = 0
-    begin
-      s.readpartial(1024 * 1024, buf)
-      slow.update(buf)
-      n += buf.bytesize
-      sleep 0.01
-    rescue EOFError
-      s = s.close
-    end while s
-    ft.join(5)
-    assert_equal [n, slow.hexdigest ], ft.value
-
-    fast = Digest::MD5.new
-    f = TCPSocket.new(host, port)
-    f.write(req)
-    check_headers(f)
-    begin
-      f.readpartial(1024 * 1024, buf)
-      fast.update(buf)
-    rescue EOFError
-      f = f.close
-    end while f
-    buf.clear
-    assert_equal slow.hexdigest, fast.hexdigest
   ensure
-    s.close if s
+    to_close.each { |io| io.close unless io.closed? }
     quit_wait(pid)
     quit_wait(pid2)
   end

^ permalink raw reply related	[relevance 5%]

* [PATCH \0/5] another round of proxy-related bugfixes!
@ 2016-06-07  7:39  6% Eric Wong
  2016-06-07  7:39  5% ` [PATCH 5/5] proxy_pass: fix HTTP/1.0 backends on EOF w/o buffering Eric Wong
  0 siblings, 1 reply; 4+ results
From: Eric Wong @ 2016-06-07  7:39 UTC (permalink / raw)
  To: yahns-public

2/5 and 3/5 are generic fixes which may apply to maint.
And yes, even fixed a bug in the PSGI app I'm proxying
(which hosts are mail archives, and soon our git repo).

The next thing to be smarter about avoiding temporary files
entirely with "proxy_buffering: false".  But I'll leave the
currently running code as is for a day or so, first.

Anyways, yahns should be able to handle HTTPS termination
for arbitrarily large responses without touching the FS.
But generating the arbitrarily large responses efficiently
(outside of yahns/Ruby) is still tricky :x

Eric Wong (5):
      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

 lib/yahns/fdmap.rb                   |  11 ++-
 lib/yahns/proxy_http_response.rb     |  17 ++--
 lib/yahns/queue_epoll.rb             |   1 +
 lib/yahns/queue_kqueue.rb            |   1 +
 lib/yahns/req_res.rb                 |   6 +-
 lib/yahns/server.rb                  |   3 +-
 lib/yahns/server_mp.rb               |   2 +-
 lib/yahns/wbuf_lite.rb               |   7 +-
 test/test_proxy_pass.rb              |   4 +-
 test/test_proxy_pass_no_buffering.rb | 145 +++++++++++++++++++----------------
 test/test_server.rb                  |  35 +++++++++
 11 files changed, 150 insertions(+), 82 deletions(-)

^ 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-06-07  7:39  6% [PATCH \0/5] another round of proxy-related bugfixes! Eric Wong
2016-06-07  7:39  5% ` [PATCH 5/5] proxy_pass: fix HTTP/1.0 backends on EOF w/o buffering Eric Wong
2016-06-14 19:41  7% [PATCH] wbuf_common: reset offset counter when done Eric Wong
2016-08-05  7:44  6% [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).