You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem is the way ruby calculate stacksize for main thread and what musl reports as available via the non-portable pthread_getattr_np() call. Musl will give you the memory size that is guaranteed by kernel while glibc gives you the number you will "hopefully" get.
@ncopa is there a config variable we could throw, during the make/compilation phase, to increase that size? I'm just wondering if this is a viable solution/workaround at this point.
No, that is sort of the problem. The stack size is big enough, (sort of) but it the way musl reports it. A possible workaround would be to implement ruby's own pthread_getattr_np() and use that when current thread (pthread_self()) is the same as main thread. (syscall(SYS_gettid) == getpid()) and fallback to libc's phread_getattr_np() when its not main thread.
The code there is already messy as it is and "fixing" it or adding a workaround in ruby will make it worse 😞 What ruby tries to do here is somewhat controversial in the first place. Kernel could still deny ruby the stack memory it believes it has available.
It may look like __APPLE__ systems have similar problem? I need to investigate why they do the check if (pthread_equal(th->thread_id, native_main_thread.id)). Thats the logic we need: if current thread is main thread, then use getrlimit(RLIMIT_STACK)
Is it possible to apply the patch from @ncopa within a Dockerfile using the ruby:2.5.1-alpine image? The larger debian images are compounding and making quite a difference in our CI builds.
Reacted by Eric Bailey, Christoph Wagner, andy shaw, Amadeus Folego and Mark Allen
When will this change get pushed to Docker Hub? I see here that the images on Docker Hub are still built using this commit from BEFORE the PR merge. The last time the official images were built was 11 days ago.
Activity
ncopa commentedon Mar 9, 2018
Testcase:
Problem is the way ruby calculate stacksize for main thread and what musl reports as available via the non-portable
pthread_getattr_np()call. Musl will give you the memory size that is guaranteed by kernel while glibc gives you the number you will "hopefully" get.Daniel-ltw commentedon Mar 11, 2018
@ncopa is there a config variable we could throw, during the make/compilation phase, to increase that size? I'm just wondering if this is a viable solution/workaround at this point.
ncopa commentedon Mar 12, 2018
No, that is sort of the problem. The stack size is big enough, (sort of) but it the way musl reports it. A possible workaround would be to implement ruby's own
pthread_getattr_np()and use that when current thread (pthread_self()) is the same as main thread. (syscall(SYS_gettid) == getpid()) and fallback to libc'sphread_getattr_np()when its not main thread.The code there is already messy as it is and "fixing" it or adding a workaround in ruby will make it worse 😞 What ruby tries to do here is somewhat controversial in the first place. Kernel could still deny ruby the stack memory it believes it has available.
Daniel-ltw commentedon Mar 12, 2018
This is kind of frustrating as I have static code analysis failing on the stack size and I have fall back to ruby 2.4 for that.
The normal application test do run fine with 2.5.
ncopa commentedon Mar 13, 2018
Possible workaround:
It may look like
__APPLE__systems have similar problem? I need to investigate why they do the checkif (pthread_equal(th->thread_id, native_main_thread.id)). Thats the logic we need: if current thread is main thread, then usegetrlimit(RLIMIT_STACK)ncopa commentedon Mar 14, 2018
The workaround will omit the
reserve_stackthing on linux. A proper fix based on http://www.openwall.com/lists/musl/2013/03/31/10:main/ruby: fix calculation of stack size for main thread
jottr commentedon Apr 5, 2018
Any updates on this? Will this be fixed upstream instead?
Thank you for working on this!
ncopa commentedon Apr 5, 2018
I did send the patch to https://bugs.ruby-lang.org/issues/14387#change-70914 but I haven't got any response. Maybe ask for response there?
The problem is not too complicated to understand, but understanding how to properly fix it is a bit complicated.
Daniel-ltw commentedon Apr 6, 2018
@ncopa Should we get this patch applied at this level for now as it will still affect ruby 2.5.0 and ruby 2.5.1?
This is so that downstream users get the fix for now and it will not affect other OS users from this level.
ncopa commentedon Apr 10, 2018
yes, i think this patch should be applied at this level.
Daniel-ltw commentedon Apr 10, 2018
As for, when the ruby lang team wants to apply the patch, let them ponder on that, as you have already release what you think is an appropriate patch.
I guess all contributor now have to be conscious that there is this patch for ruby 2.5 that is needed.
tianon commentedon May 16, 2018
I'm still a little bit wary of applying the patch at this level, especially given that upstream doesn't seem keen on it. 😞
Daniel-ltw commentedon May 16, 2018
@tianon I guess this issue currently on affects alpine due to the use of musl c.
Upstream does not seem to be concern as majority of the users are on glibc which does not really affect them.
Based on @ncopa patch, this should work nicely with musl c as Yui Naruse said. As for other non glibc platforms, this might not be the right patch.
Daniel-ltw commentedon Jun 7, 2018
@ncopa https://bugs.ruby-lang.org/issues/14387#note-19
New reply in regards to your patch.
stephendolan commentedon Aug 31, 2018
Is it possible to apply the patch from @ncopa within a Dockerfile using the
ruby:2.5.1-alpineimage? The larger debian images are compounding and making quite a difference in our CI builds.t-anjan commentedon Oct 1, 2018
When will this change get pushed to Docker Hub? I see here that the images on Docker Hub are still built using this commit from BEFORE the PR merge. The last time the official images were built was 11 days ago.
Upgrade Ruby to 2.5.1
Upgrade Ruby to 2.5.1
Upgrade Ruby to 2.5.1