mongo shell crashes at init with an out of memory error
With version >3.2.4, mongo shell crashes at init with an out of memory error.
This was occuring before (see #5117) but the workaround proposed at that time does not work anymore and the source of the problem must be fixed, not the symptom.
The source of the problem is that the default stacksize (80 kb) is too small, and can not be changed. The reason is that the mongo shell, based on mozjs, is using std::thread, which does not allow to set the stacksize at thread creation (std::thread create threads by invoking pthread_create with a null attribute, thus relying on system defaults).
The behaviour of musl libc is to assign a fixed default stacksize, contrary to glibc implementation which has a default size of 2MB or relies on system stack limit (ulimit -s) if it has not an unlimited value (it is usually 8MB).
The only way to set the stacksize per application is to call pthread_attr_setstacksize() prior to pthread_create(), which is inoperant in the case of mongo shell, or any c multithreaded program relying on std::thread, the standard c lib (so huge impact).
What should be discussed now, beyond just mongo shell, is how to properly fix this. Ultimately, I think that the solution should be implemented in musl, in order to offer a way to programs relying on std::thread to set the stacksize. Another possibility would be to fix std::thread to explicitely using ulimit (but it’s really not nice).
In the meantime, the last version of mongodb where mongo shell is working properly is 3.2.4. This package should be reverted to this version.
(from redmine: issue id 6187, created on 2016-09-19, closed on 2017-05-22)
- Changesets:
- Revision f105a8c5 by Timo Teräs on 2016-11-01T11:31:02Z:
testing/mongodb: various fixes
- fixes #6187
- paxmark all executables for JIT to work
- increase default stack size for std::thread compatiblity
- fix to compile with boost 1.62