Open straight-shoota opened 5 years ago
Stack overflow detection relies on the current thread's stack bounds. On Linux this is obtained using LibC.pthread_getattr_np
and LibC.pthread_attr_getstack
:
However, on musl-libc the internal stack size is always hardcoded to a very small default of 128 KiB, and pthread_getattr_np
returns this value unmodified, presumably for the main thread as well. The result is that the main thread has an entirely incorrect @stack
, as it respects ulimit -s
, and that non-main threads are really that small, as we don't pass any attr
to GC.pthread_create
on thread creation. This is also mentioned on Ruby's bug tracker.
The stack trace itself is wrong as well, even though Exception::CallStack.print_backtrace
works correctly as long as it is outside a signal handler. This appears to be an intentional won't-fix. If we need a meaningful stack trace inside a signal handler then we have to bypass _Unwind_Backtrace
and mimic whatever a debugger like LLDB does.
6928 added a cool feature which detects whether an invalid memory access is actually a stack overflow error.
However, this detection does not yet seem to work correctly in all cases.
On alpine edge the spec for SO detection on main stack fails:
The spec for SO detection on fiber stack passes, though.
There was a similar failure reported for Ubuntu 14.04 which doesn't seem to have been fixed (https://github.com/crystal-lang/crystal/pull/6928#issuecomment-430530379).
If this can't be fixed right away, a short term play would be to simply disable the spec on affected platforms. They're not essential.
/cc @damaxwell