trysetrlimit always raises on Mac OS X

Claudio Poli claudio at
Thu Sep 15 21:43:09 EDT 2011

I decided to investigate on why rainbows! prints out Invalid argument - setrlimit on Lion.

It turns out the method trysetrlimit in http_server.rb is trying to set RLIMIT_NOFILE to the maximum allowed number that it finds through cur, max = Process.getrlimit(var)

This +max+ variable holds 9223372036854775807, while 256 is the +cur+ value.
Then we find this line of code to actually set some value:
    cur <= want and Process.setrlimit(var, cur = max > want ? max : want)

This setrlimit call will do Process.setrlimit(8, 9223372036854775807), Lion bombs out and there's no fallback at least for setting the want value.

Setting Process.setrlimit second argument to the +want+ values works (mine is 406).
It should also be noted that the Process.setrlimit(2..3) call returns nil when successful.
The exact error:
    rainbows-4.3.1/lib/rainbows/http_server.rb:70:in `setrlimit': Invalid argument - setrlimit (Errno::EINVAL)

I rewrote the method a bit, but it doesn't include the fact to set the max value, ever; I understand though that other operating systems might work, so I just leave this report open for thoughts.

Currently setting this kind of limits on OSX is tricky at best and for some is not a recommended practice,
I will not be surprised if this turns out to be a Ruby bug. I'm using 1.9.3-preview1 for this tests.
iCoreTech Research Labs -

More information about the rainbows-talk mailing list