* [PATCH 0/3] various minor bugfixes
@ 2021-10-09 2:24 Eric Wong
2021-10-09 2:24 ` [PATCH 1/3] do not sleep if signals are pending Eric Wong
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Eric Wong @ 2021-10-09 2:24 UTC (permalink / raw)
To: yahns-public
It's been a while since I've run the test suite, turns out there
was a Linux kernel bug introduced and fixed which was causing
shutdown timeouts.
A couple of other minor things, too...
Eric Wong (3):
do not sleep if signals are pending
server: workaround Linux v5.5..v5.13 epoll bug
gemspec: allow unicorn 6.x
lib/yahns/queue_epoll.rb | 4 ++++
lib/yahns/server.rb | 20 ++++++++++++--------
lib/yahns/server_mp.rb | 3 ++-
yahns.gemspec | 2 +-
4 files changed, 19 insertions(+), 10 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/3] do not sleep if signals are pending
2021-10-09 2:24 [PATCH 0/3] various minor bugfixes Eric Wong
@ 2021-10-09 2:24 ` Eric Wong
2021-10-09 2:24 ` [PATCH 2/3] server: workaround Linux v5.5..v5.13 epoll bug Eric Wong
2021-10-09 2:24 ` [PATCH 3/3] gemspec: allow unicorn 6.x Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2021-10-09 2:24 UTC (permalink / raw)
To: yahns-public
This should prevent missed/delayed wakeups if repeatedly
kill(2)-ed.
---
lib/yahns/server.rb | 3 ++-
lib/yahns/server_mp.rb | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/lib/yahns/server.rb b/lib/yahns/server.rb
index d13c57e..208b5ee 100644
--- a/lib/yahns/server.rb
+++ b/lib/yahns/server.rb
@@ -476,7 +476,8 @@ def reap_reexec
end
def sp_sig_handle(alive)
- @sev.wait_readable(alive ? nil : 0.01)
+ tout = alive ? (@sig_queue.empty? ? nil : 0) : 0.01
+ @sev.wait_readable(tout)
@sev.yahns_step
case sig = @sig_queue.shift
when :QUIT, :TERM, :INT
diff --git a/lib/yahns/server_mp.rb b/lib/yahns/server_mp.rb
index 5467674..d56d1ed 100644
--- a/lib/yahns/server_mp.rb
+++ b/lib/yahns/server_mp.rb
@@ -157,7 +157,8 @@ def run_mp_worker(worker)
def mp_sig_handle(watch, alive)
# not performance critical
watch.delete_if { |io| io.to_io.closed? }
- if r = select(watch, nil, nil, alive ? nil : 0.1)
+ tout = alive ? (@sig_queue.empty? ? nil : 0) : 0.01
+ if r = select(watch, nil, nil, tout)
r[0].each(&:yahns_step)
end
case @sig_queue.shift
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/3] server: workaround Linux v5.5..v5.13 epoll bug
2021-10-09 2:24 [PATCH 0/3] various minor bugfixes Eric Wong
2021-10-09 2:24 ` [PATCH 1/3] do not sleep if signals are pending Eric Wong
@ 2021-10-09 2:24 ` Eric Wong
2021-10-09 2:24 ` [PATCH 3/3] gemspec: allow unicorn 6.x Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2021-10-09 2:24 UTC (permalink / raw)
To: yahns-public
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/
---
lib/yahns/queue_epoll.rb | 4 ++++
lib/yahns/server.rb | 17 ++++++++++-------
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/lib/yahns/queue_epoll.rb b/lib/yahns/queue_epoll.rb
index 9e4271a..a198fbf 100644
--- a/lib/yahns/queue_epoll.rb
+++ b/lib/yahns/queue_epoll.rb
@@ -32,6 +32,10 @@ def queue_mod(io, flags)
epoll_ctl(Epoll::CTL_MOD, io, flags)
end
+ def queue_del(io)
+ epoll_ctl(Epoll::CTL_DEL, io, 0)
+ end
+
def thr_init
Thread.current[:yahns_rbuf] = ''.dup
Thread.current[:yahns_fdmap] = @fdmap
diff --git a/lib/yahns/server.rb b/lib/yahns/server.rb
index 208b5ee..74eeb7e 100644
--- a/lib/yahns/server.rb
+++ b/lib/yahns/server.rb
@@ -438,25 +438,28 @@ def quit_enter(alive)
# This just injects the QueueQuitter object which acts like a
# monkey wrench thrown into a perfectly good engine :)
def quit_finish
- quitter = Yahns::QueueQuitter.new
+ # we must not let quitters get GC-ed if we have any worker threads leftover
+ @quitter = Yahns::QueueQuitter.new
# throw the monkey wrench into the worker threads
- @queues.each { |q| q.queue_add(quitter, Yahns::Queue::QEV_QUIT) }
+ @queues.each { |q| q.queue_add(@quitter, Yahns::Queue::QEV_QUIT) }
# watch the monkey wrench destroy all the threads!
# Ugh, this may fail if we have dedicated threads trickling
# response bodies out (e.g. "tail -F") Oh well, have a timeout
begin
@wthr.delete_if { |t| t.join(0.01) }
+ # Workaround Linux 5.5+ bug (fixed in 5.13+)
+ # https://yhbt.net/lore/lkml/20210405231025.33829-1-dave@stgolabs.net/
+ @wthr[0] && @queues[0].respond_to?(:queue_del) and @queues.each do |q|
+ q.queue_del(@quitter)
+ q.queue_add(@quitter, Yahns::Queue::QEV_QUIT)
+ end
end while @wthr[0] && Yahns.now <= @shutdown_expire
# cleanup, our job is done
@queues.each(&:close).clear
-
- # we must not let quitter get GC-ed if we have any worker threads leftover
- @quitter = quitter
-
- quitter.close
+ @quitter.close # keep object around in case @wthr isn't empty
rescue => e
Yahns::Log.exception(@logger, "quit finish", e)
ensure
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/3] gemspec: allow unicorn 6.x
2021-10-09 2:24 [PATCH 0/3] various minor bugfixes Eric Wong
2021-10-09 2:24 ` [PATCH 1/3] do not sleep if signals are pending Eric Wong
2021-10-09 2:24 ` [PATCH 2/3] server: workaround Linux v5.5..v5.13 epoll bug Eric Wong
@ 2021-10-09 2:24 ` Eric Wong
2 siblings, 0 replies; 4+ messages in thread
From: Eric Wong @ 2021-10-09 2:24 UTC (permalink / raw)
To: yahns-public
The changes in unicorn 6.x don't affect us
---
yahns.gemspec | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/yahns.gemspec b/yahns.gemspec
index 5752ad8..3808061 100644
--- a/yahns.gemspec
+++ b/yahns.gemspec
@@ -15,7 +15,7 @@
s.add_dependency(%q<kgio>, '~> 2.9')
s.add_dependency(%q<sleepy_penguin>, '~> 3.2')
- s.add_dependency(%q<unicorn>, '>= 4.6.3', '< 6.0')
+ s.add_dependency(%q<unicorn>, '>= 4.6.3', '< 7.0')
# s.add_dependency(%q<kgio-sendfile>, '~> 1.2') # optional
# minitest is standard in Ruby 2.0, 4.3 is packaged with Ruby 2.0.0,
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-10-09 2:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-09 2:24 [PATCH 0/3] various minor bugfixes Eric Wong
2021-10-09 2:24 ` [PATCH 1/3] do not sleep if signals are pending Eric Wong
2021-10-09 2:24 ` [PATCH 2/3] server: workaround Linux v5.5..v5.13 epoll bug Eric Wong
2021-10-09 2:24 ` [PATCH 3/3] gemspec: allow unicorn 6.x 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).