yahns Ruby server user/dev discussion
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: yahns-public@yhbt.net
Subject: [PATCH] test/test_client_expire: fix for high RLIMIT_NOFILE
Date: Sun, 15 May 2016 08:41:40 +0000	[thread overview]
Message-ID: <20160515084140.31239-1-e@80x24.org> (raw)

The ab(1) command we use for testing is limited to 20000 open
connections under Debian jessie; a perfectly reasonable limit
to avoid port exhaustion.  I never noticed this limit before,
but systemd under Jessie seems to have upped the default
RLIMIT_NOFILE to 65536(!), causing ab to error out.

We don't even need 10K connections for testing,
we just need to hit *some* limit before we start expiring.
So lower the RLIMIT_NOFILE back to 1024 in the forked server
process so we can test more quickly without running out of
ports or memory, since exhausting the 65536 RLIMIT_NOFILE
limit is not going to happen with a single TCP address.
---
 test/test_client_expire.rb | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/test/test_client_expire.rb b/test/test_client_expire.rb
index b2f932b..b6dec1a 100644
--- a/test/test_client_expire.rb
+++ b/test/test_client_expire.rb
@@ -99,6 +99,14 @@ def test_client_expire_desperate
       end
       stderr_path err.path
     end
+
+    # 1024 is common on old systems, but nowadays Jessie seems to be 65536
+    nr = Process.getrlimit(:NOFILE)[0]
+    if nr >= 1024
+      nr = 1024
+      do_rlimit = true
+    end
+
     pid = mkserver(cfg) do
       keep = { $stderr => true, $stdout => true, $stdin => true, @srv => true }
       ObjectSpace.each_object(IO) do |obj|
@@ -108,7 +116,9 @@ def test_client_expire_desperate
         rescue IOError # could be uninitialized
         end
       end
+      Process.setrlimit(:NOFILE, nr) if do_rlimit
     end
+
     f = get_tcp_client(host, port)
     f.write "G"
     s = get_tcp_client(host, port)
@@ -119,10 +129,9 @@ def test_client_expire_desperate
     assert_match(%r{keep-alive}, str)
     sleep 1
 
-    # ignore errors, just beat the crap out of the process
-    nr = Process.getrlimit(:NOFILE)[0] # 1024 is common
     assert_operator nr, :>, 666, "increase RLIM_NOFILE (ulimit -n)"
     nr -= 50
+    # ignore errors, just beat the crap out of the process
     opts = { out: "/dev/null", err: "/dev/null", close_others: true }
     begin
       pids = 2.times.map do

                 reply	other threads:[~2016-05-15  8:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/yahns/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160515084140.31239-1-e@80x24.org \
    --to=e@80x24.org \
    --cc=yahns-public@yhbt.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).