Greetings,
I’m sure that there are many project maintainers and OS X/Ruby users
who will be interested in what I have discovered.
Like many OS X/Ruby users, I too was bitten by the “stack level too
deep” error when running some scripts. Based on my own limited
experience, the bug happened when running Unit::Test and scripts that
use the REXML library.
The fix so far was to add a line to your .profile (or .tcshrc if you’re
using tcsh) that looked like one of the following: (assuming an 8K
stack size)
limit stacksize 8192 # tcsh
ulimit -s 8192 #bash/sh
Currently the stack size in OS X is 512 bytes. As a point of
comparison, Linux enjoys a 32K stack size.
However, this fix did not work in all environments. For example, if
you wrote a cgi script that was deeply recursive (as an example), you
would get the dreaded “stack level too deep” error - because Apache
still thinks the stack size is 512 bytses.
I put the question about how to increase the stack size to the Apple
Discussion forum (http://discussions.info.apple.com/, click "Mac OS X"
under System Software Discussions; click “Unix” (2nd from the bottom);
look for ““Stack Level Too Deep” error and Apache”), and got a very
interesting answer.
/etc/rc.common is one of the first scripts in OS X that gets executed.
It’s a sh script, so if you add:
ulimit -s 8192
to the bottom of it, then restart the machine, then the stack size will
be big enough to run many more ruby scripts. Don’t use the tcsh
equivalent (limit stacksize 8192), because at this point you’re running
an sh script, not a tcsh script.
As a gentle reminder for those people who like to keep their config
files clean: If you make this modification to rc.common, and you
already modified your shell profile with a line like this, you might
want to remove that line from your profile.
see ya,
-rh