Mail archive
alpine-aports

Re: [alpine-aports] [PATCH] testing/mongodb: fix bug #5117 where mongo fails at start

From: Timo Teras <timo.teras_at_iki.fi>
Date: Tue, 23 Feb 2016 18:20:10 +0200

On Tue, 23 Feb 2016 17:10:44 +0100
Marc Vertes <marc.vertes_at_ugrid.net> wrote:

> > Le 23 févr. 2016 à 16:50, Timo Teras <timo.teras_at_iki.fi> a écrit :
> >
> > On Tue, 23 Feb 2016 16:35:58 +0100
> > Marc Vertes <marc.vertes_at_ugrid.net> wrote:
> >
> >> No success. I think that the base address returned by
> >> pthread_attr_getstack(&attr, &base, &size) is the problem.
> >> Increasing the size (like with getrlimit) doesn't change the test
> >> in StackLocator.available() which triggers abort: it checks the
> >> available space against this base address (&localaddr - base >
> >> quota).
> >>
> >> Changing size does nothing.
> >>
> >> I also noticed that pthread_getattr_np and pthread_attr_getstack
> >> where not performed from the main thread (gettid != getpid)
> >
> > Right. ulimit should be used only for main thread. Not the created
> > threads with libc allocated stack. That needs a fix.
> >
> > pthread_attr_getstack should return the lowest addressable byte of
> > the stack. So indeed, if we change the size, we need to adjust base
> > accordingly on system with downward growing stack. Something like:
> >
> > ---
> > mongodb-src-r3.2.1.orig/src/mongo/platform/stack_locator_pthread_getattr_np.cpp
> > +++
> > mongodb-src-r3.2.1/src/mongo/platform/stack_locator_pthread_getattr_np.cpp
> > _at_@ -31,6 +31,7 @@ #include "mongo/platform/stack_locator.h"
> >
> > #include <pthread.h>
> > +#include <sys/resource.h>
> >
> > #include "mongo/util/assert_util.h"
> > #include "mongo/util/scopeguard.h"
> > _at_@ -52,6 +53,13 @@
> > invariant(result == 0);
> > invariant(base != nullptr);
> > invariant(size != 0);
> > +
> > + struct rlimit rl;
> > +
> > + base += size;
> > + invariant(getrlimit(RLIMIT_STACK, &rl) == 0);
> > + size = rl.rlim_cur ? : 2 * 1024 * 1024;
> > + base -= size;
> >
> > // TODO: Assumes a downward growing stack. Note here that
> > // getstack returns the stack *base*, being the bottom of the
> >
>
> This one works!
> But I'm afraid of possible stack overlap between threads if it is run
> not from main thread. Is it your concern too ?

For non-main threads we should not use rlimit. the rlimit stuff should
be in if (something) so that it is triggered for main thread only.

For main thread the ulimit should be safe. Kernel should create
mappings in such a way that they don't overlap. In fact, glibc uses
getrlimit(RLIMIT_STACK) inside pthread_getattr_np call to calculate
base exactly this way.

/Timo



---
Unsubscribe:  alpine-aports+unsubscribe_at_lists.alpinelinux.org
Help:         alpine-aports+help_at_lists.alpinelinux.org
---
Received on Tue Feb 23 2016 - 18:20:10 GMT