about summary refs log tree commit homepage
path: root/lib
DateCommit message (Collapse)
2021-10-09server: workaround Linux v5.5..v5.13 epoll bug
epoll_wait() wakeups from QueueQuitter got lost during graceful shutdown since there's multiple worker threads operating off the same FD. Workaround the problem by re-arming the eventfd for every worker thread reaped. Link: https://yhbt.net/lore/lkml/20210405231025.33829-1-dave@stgolabs.net/
2021-10-09do not sleep if signals are pending
This should prevent missed/delayed wakeups if repeatedly kill(2)-ed.
2019-05-10proxy_pass: document as a public API
Might as well... this has been in use at YHBT.net for ~4 years at this point. And given nginx has new corporate overlords, maybe a decidedly non-enterprisey alternative is worth "marketing" :P Previous discussion from 2016: https://YHBT.net/yahns-public/20160220081619.GA10850@dcvr.yhbt.net/
2019-05-04worker: workaround old F_SETPIPE_SZ bug
Linux before 4.9 (and before 3.16.57) failed to account for the existing size of a pipe before checking system resource limits and would return EPERM in that case. https://80x24.org/mirrors/linux.git/commit?id=b0b91d18e2e97b741b294af9333824ecc3fadfd8 https://lore.kernel.org/lkml/?q=s%3A%22fix+limit+checking+in+pipe_set_size%22 Based on a patch by Stephen Demjanenko for unicorn: https://bogomips.org/unicorn-public/1556922018-24096-1-git-send-email-sdemjanenko@gmail.com/
2019-04-21doc: update homepage to point to cgit install
I've gotten cgit to work well for browsers without CSS support (patches posted to <cgit@lists.zx2c4.com>). For browsers with CSS support, the color scheme is now dark and can help save electricity for users of OLED and CRT displays.
2019-04-02sigevent_*: fixup non-eventfd path
And slightly cleanup the Kgio::DefaultWaiters include for the eventfd path, too. Fixes: 96825e8ca734cfbb ("remove calls to kgio_wait_* able")
2019-01-08do not shutdown until listeners are all stopped
Otherwise, listeners may still be injecting into the queue and new clients may be accepted. Fixes: 86ea6ed1417b ("server: respect shutdown_timeout")
2019-01-07remove calls to kgio_wait_* able
IO#wait_readable existed since Ruby 2.0, so we don't need to use the "kgio_"-prefixed version.
2019-01-05worker: rely on F_SETPIPE_SZ to set mininum value
Old kernels running on alpha may EINVAL, here; but modern kernels will automatically increase the passed value to the minimum size supported by the kernel. This only affects alpha, since all other arches use 4K page size on Linux.
2019-01-05wbuf: use IO#write directly in Ruby 2.5+ for writev
Slowly removing kgio dependencies...
2018-12-30server: extra shutdown timeout debugging
Still not sure what's going on with the proxy_pass code, but something in the Fdmap code is causing shutdowns to take way longer than expected...
2018-12-30server: respect shutdown_timeout
It seems there is still a bug in the proxy code which causes this timeout expiries to be missed.
2018-12-28server_mp: remove redundant srand call
Ruby itself has tests for RNG reseeding at fork, so no need for belt-and-suspenders code on our end.
2018-12-28server_mp: favor "Kernel#select" instead of "IO.select"
Golfing to eliminate a constant lookup and inline-constant-cache entry
2018-12-13yahns/worker: shrink pipe under Linux
We use eventfd whereever possible, but workers still require a pipe to the parent for death detection.
2018-12-08remove IO#close_on_exec= calls
Since we've required Ruby 2.0+ for a while, we can assume descriptors are created with IO#close_on_exec=true and avoid bloating our code with calls to it.
2018-12-08http_client: do not warn on do_pread overreach
Without sendfile, we can hit EOFError on IO#pread if a file we're serving gets truncated mid-response. This was causing test_truncated_sendfile failures; but I didn't notice before because I forgot to set SENDFILE_BROKEN=1 to disable the test.
2018-12-08Add QueueQuitter#closed? to queue_quitter_pipe.rb
Since we rely on this class being an IO-like class, in Yahns::Queue#worker_thread we're using this method. This fixes an actual error on lib/yahns/queue_kqueue.rb:56
2018-08-05use IO#pread if available in Ruby 2.5
In the future, this will allow sharing open files across different clients when serving static files. For now, it saves us one syscall.
2018-08-05openssl_client: do not attempt writes after SystemCallError
Whenever @ssl.write_nonblock fails due to ECONNRESET/EPIPE in Rack::Deflater#each; Rack::Deflater#each will still attempt to write again in the "ensure" statement via Zlib::GzipWriter#close. This causes SSL_write to complain of "bad length" or "bad write retry" errors. Now, re-raise any SystemCallError we caught from previous write_nonblock calls to prevent calls to SSL_write which would trigger such an exception.
2018-08-05http_client: clear backtrace on "wrong version number" in OpenSSL
Errors which are the fault of the client should not generate backtraces which can lead to dinky servers running out-of-space.
2017-04-20server: fix incomplete comment about SSLContext#setup
Oops. Occasionally my brain experiences packet loss :x
2017-04-06allow omitting specifying socket name when inheriting listen socket
Since the common case is still to run a single app inside yahns, we can simplify setup a bit for systemd (and like) users by allowing them to omit the "listen" directive when they are running a single app in yahns.
2017-04-05rackup_handler: remove unnecessary branch
No point in optimizing for the single listener case in setup code.
2017-04-03avoid Thread#[] and Thread#[]= across threads
Support for it may be removed in future versions of Ruby(*), and we actually do not need to waste time looping when a instance variable will do. (*) https://bugs.ruby-lang.org/issues/13245
2017-04-03USR2 upgrades may use Process.spawn for vfork
Remove false statements about close-on-exec being cleared in the parent process (verified via strace) and refactor the code to take full advantage of options for Process.spawn and Process.exec. This avoids unnecessary CoW traffic for the common case where before_exec is unset.
2017-04-03proxy_pass: comment explaining what rack.hijack calls
"call" is a generic name and may not obvious to somebody new to the code.
2017-04-03config: more descriptive variable name
That object is not a Rack app, so lets avoid confusing ourselves.
2017-03-05chunk_body: nodoc this internal class
Although we do not publish RDoc-generated documentation on our website, other places may, an people use ri(1) locally.
2017-02-17http_response: make response headers eligible for GC, sooner
Iterating through the response body can be time consuming and allocate memory, so nil out the headers object when we're done with it to give Ruby a chance to recover the memory.
2016-12-31proxy_http_response: reduce memory pressure from larger headers
We try to cleanup after ourselves if possible so future mallocs can find memory more easily. We do not need to nil the object slot, just String#clear since we're exiting the function soon, anyways. Followup to commit bb774680aae0a827f887761b18da304aa94111cc ("use String#clear for short-lived buffers we create")
2016-12-31tee_input: simplify conditional for writing to temporary file
It's rare to have an empty string returned by `read` since it requires a length argument of zero (careless) or nil (danger! OOM!). Lets not try to optimize away a method dispatch in this case by checking .size (optimized instruction in YARV). Ruby IO#write already treats writing an empty string as a noop, so no syscall is saved. n.b. `gets` can return an empty string, too, but that's also dangerous w.r.t. memory usage on untrusted input.
2016-12-29proxy_pass: add a note about the instability of this
In case somebody stumbles upon it...
2016-12-29stream_input: avoid allocation for common #read case
When entering StreamInput#read, it is common for @rbuf to be drained and empty, meaning a simple String#clear can be used in place of a more complex String#slice! String#replace combo on an empty @rbuf. While we're at it, we'll avoid an extra instructions for calling `@rbuf.size` by storing the size in a local.
2016-12-14proxy_pass: do not chunk on bodyless upstream responses
As with the previous commit ("response: do not set chunked header on bodyless responses"), blindly setting "Transfer-Encoding: chunked" is wrong and confuses "curl -T" on 204 responses, at least.
2016-12-14response: do not set chunked header on bodyless responses
Setting "Transfer-Encoding: chunked" on responses will confuse clients which see a 204 response and do not expect a body. This follows Rack::Chunked behavior, as yahns should function without Rack::Chunked middleware. This regression appeared in yahns v1.13.0 (2016-08-05)
2016-11-29http_response: support rack.hijack on HTTP/0.9 responses
We still need to iterate through all response headers to support response-only Rack hijacking. Previously, we only supported full hijacking on so-called "HTTP/0.9" clients. n.b. This diff will be easier to read with the -b/--ignore-space-change option of git-diff(1) or GNU diff(1)
2016-11-29queue_*: fix outdated comments
These comments have been outdated since 2013 with commit cd84e2ccbdf2 ("ensure we stop all threads at exit")
2016-11-12req_res: do not send 502 on catchall error if response buffered
If we already started writing a response, we cannot be sending a 502 to inform a user a connection has failed. This should prevent errors from the OpenSSL layer about mismatched buffers due to the combination of slow clients and upstreams prematurely aborting.
2016-11-11response: fixup compile error
Introduced in commit 08cea89483e90c79daa2c8efe70da6bdeba71147 ('response: only stream "file" responses on known length')
2016-11-08response: only stream "file" responses on known length
This means we need to check Content-Length and use it properly (unless Content-Range is set).
2016-11-08stream_file: remove #to_io support from responses
This is not a part of any Rack specification, and can lead to interesting bugs with wrapped classes for gzip and TLS. AFAIK, .to_io was meant to support IO#wait_*able and IO.select methods, not to actually perform read/writes on the return value.
2016-09-26move website to https://yhbt.net/yahns/
HTTPS adds some level of privacy protection and helps marketing (because we care soooo much about good marketing! :P). Performance-wise, this reduces subjectAltName bloat when negotiating connections and will also speed up occasional certificate renewals when/if we drop the old name. Also, not occupying the document root of a domain will make it easier to add alternative site locations in the future, because centralization sucks and I don't like the idea of anybody paying ICANN or similar entities for domain names.
2016-08-06openssl_client: avoid undefined SSL_write behavior
Sometimes apps may trigger zero-byte chunks in the response body for whatever reason. We should maintain consistent behavior with the rest of kgio; and Ruby OpenSSL::SSL::SSLSocket should maintain consistent behavior with the core IO class: https://bugs.ruby-lang.org/issues/12660
2016-08-03response: support auto-chunking for HTTP/1.1
We might as well do it since puma and thin both do(*), and we can still do writev for now to get some speedups by avoiding Rack::Chunked overhead. timing runs of "curl --no-buffer http://127.0.0.1:9292/ >/dev/null" results in a best case drop from ~260ms to ~205ms on one VM by disabling Rack::Chunked in the below config.ru $ ruby -I lib bin/yahns-rackup -E none config.ru ==> config.ru <== class Body STR = ' ' * 1024 * 16 def each 10000.times { yield STR } end end use Rack::Chunked if ENV['RACK_CHUNKED'] run(lambda do |env| [ 200, [ %w(Content-Type text/plain) ], Body.new ] end) (*) they can do Content-Length, but I don't think it's worth the effort at the server level.
2016-08-03response: reduce stack overhead for parameter passing
This makes it easier to add more parameters to http_response_write and simplifies current callers.
2016-08-03response: drop clients after HTTP responses of unknown length
Clients are not able to handle persistent connections unless the client knows the length of the response.
2016-07-26http_response: drop bodies for non-compliant responses
Rack::Lint-compliant applications wouldn't have this problem; but apparently public-facing Rack servers (webrick/puma/thin) all implement this; so there is precedence for implementing this in yahns itself.
2016-07-20wbuf_lite: clear @busy flag when re-arming
This allows us to speed up subsequent calls to wbuf_write when the client socket buffers are cleared. This doesn't affect functionality outside of performance.
2016-07-20wbuf_lite: reset sf_offset/sf_count consistently
Since we use wbuf_lite for long, streaming requests, we need to reset the offset and counts when aborting the existing wbuf and not assume the wbuf goes out-of-scope and expires when we are done using it. Fix stupid bugs in BUG notices while we're at it :x