Bug #19716
closedSystemStackError occurs too easily on Alpine Linux (due to small stack size reported by pthread_attr_getstacksize on musl libc)
Description
This is the same problem previously reported against Ruby 2.5 in https://bugs.ruby-lang.org/issues/14387. I just ran into the same problem on Ruby 3.1.4, built on Alpine Linux 3.16.
@hsbt (Hiroshi SHIBATA) stated in the previous thread (https://bugs.ruby-lang.org/issues/14387#note-28):
If you have this issue with Ruby 3.2, please file it with another issue.
I hacked stack_check
in gc.c to print the values of STACK_START
and STACK_END
on stack overflow; on the Alpine 3.16 host where this problem just occurred, the values printed were:
Start=0x7ffd0bf4f000, End=0x7ffd0bf32530
...which shows that Ruby thinks the stack size is only 131072 bytes. On the other hand, ulimit -s
shows a stack size limit of 8192kb.
This Ruby 3.1.4 was built from unmodified source code downloaded from https://cache.ruby-lang.org; the build was configured using CFLAGS='-march=native' ./configure --disable-install-doc
.
The invocation of Ruby which blew the stack was bundle exec rake db:migrate
, on a mid-sized Rails project.
Regarding @ncopa's patch from #14387, @wanabe (_ wanabe) listed some things which should be done before it is merged into mainline Ruby:
Okay, The patch needs one or more proofs of its behaviour, like that:
Original issue [ruby-dev:50421] has gone away.
Standard test codes run well.
test-all
ruby/spec
getrlimit works on some situations like:
on single thread
with multiple threads
with RLIMIT_STACK environment variable
getrlimit code of musl is implemented correctly as expected.
(But It's doubtful whether it can be. I guess that a proof of code soundness is very difficult.)
Some "real world" applications can work.
I think it is better example that that application(s) can't work without the patch.
I am happy to help cover some of these points if the Ruby development team is still interested in merging @ncopa's patch.