diff options
author | Eric Wong <bofh@yhbt.net> | 2023-09-05 06:43:20 +0000 |
---|---|---|
committer | Eric Wong <bofh@yhbt.net> | 2024-01-15 01:45:45 +0000 |
commit | b652fa51c1342496bdcdecca8e567f1fb46c41c9 (patch) | |
tree | b10a1dd61bdf0c4b253600ab38dbfbc311da93ed /lib/unicorn/worker.rb | |
parent | 31d0539878b0e2247a4f98bc0241e05d4738e500 (diff) | |
download | unicorn-b652fa51c1342496bdcdecca8e567f1fb46c41c9.tar.gz |
kgio is an extra download and shared object which costs users bandwidth, disk space, startup time and memory. Ruby 2.3+ provides `Socket#accept_nonblock(exception: false)' support in addition to `exception: false' support in IO#*_nonblock methods from Ruby 2.1. We no longer distinguish between TCPServer and UNIXServer as separate classes internally; instead favoring the `Socket' class of Ruby for both. This allows us to use `Socket#accept_nonblock' and get a populated `Addrinfo' object off accept4(2)/accept(2) without resorting to a getpeername(2) syscall (kgio avoided getpeername(2) in the same way). The downside is there's more Ruby-level argument passing and stack usage on our end with HttpRequest#read_headers (formerly HttpRequest#read). I chose this tradeoff since advancements in Ruby itself can theoretically mitigate the cost of argument passing, while syscalls are a high fixed cost given modern CPU vulnerability mitigations. Note: no benchmarks have been run since I don't have a suitable system.
Diffstat (limited to 'lib/unicorn/worker.rb')
-rw-r--r-- | lib/unicorn/worker.rb | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/lib/unicorn/worker.rb b/lib/unicorn/worker.rb index ad5814c..4af31be 100644 --- a/lib/unicorn/worker.rb +++ b/lib/unicorn/worker.rb @@ -71,8 +71,8 @@ class Unicorn::Worker end # this only runs when the Rack app.call is not running - # act like a listener - def kgio_tryaccept # :nodoc: + # act like Socket#accept_nonblock(exception: false) + def accept_nonblock(*_unused) # :nodoc: case buf = @to_io.read_nonblock(4, exception: false) when String # unpack the buffer and trigger the signal handler @@ -82,7 +82,7 @@ class Unicorn::Worker when nil # EOF: master died, but we are at a safe place to exit fake_sig(:QUIT) when :wait_readable # keep waiting - return false + return :wait_readable end while true # loop, as multiple signals may be sent end |