You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Justin C. Darby" <wi...@kradaudio.net> on 2001/10/31 20:30:54 UTC

libmysqlclient and apache2

I'm writing a C++ apache module for httpd-2.0, and I'm running into a bit
of a wall with Apache's memory allocation system.

It appears that whenever the mysql client library tries to malloc()
memory, it causes the server to crash.

When I call mysql_options(), it's crashing in the call to my_malloc(), in
mysys/my_malloc.c, line 36 (mysql 2.23.43). It's a perfectly harmless
malloc() call, done in a thread-safe build of the mysql client library
(which is why I'm blaming Apache before MySQL here..).

Over-detailed bloated gdb/strace/etc available if needed, however, I was
able to reproduce this on every assorted linux box in my office.

Any ideas?

Thanks,
Justin C. Darby



Re: libmysqlclient and apache2

Posted by "Justin C. Darby" <wi...@kradaudio.net>.
I get the same exact result with the prefork MPM, the 'worker' MPM crashes
like so:

[New Thread 27676 (LWP 20127)]
Delayed SIGSTOP caught for LWP 20127.
LWP 20101 exited.

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 3076 (LWP 20103)]
top_check () at malloc.c:4607
4607    malloc.c: No such file or directory.
        in malloc.c
(gdb)

The backtrace..

#0  top_check () at malloc.c:4607
#1  0x40261d25 in malloc_check (sz=11, caller=0x4033937e) at malloc.c:4645
#2  0x4025f06d in __libc_malloc (bytes=11) at malloc.c:2798
#3  0x4033937e in my_malloc (Size=11, MyFlags=16) at my_malloc.c:36
#4  0x4033958f in my_strdup (from=0x403278c0 "WebSession", MyFlags=16)
    at my_malloc.c:81
#5  0x40336a23 in mysql_options (mysql=0x40313a08,
    option=MYSQL_READ_DEFAULT_GROUP, arg=0x403278c0 "WebSession")
    at libmysql.c:2283
#6  0x403210a3 in TMySQLSet::Configure (this=0x81a42f8)
    at classtemplate/TMySQLSet.tmpl:26

Keep in mind this is happening in the C++ constructor, nothing else gets
free'd or malloc'd before this class is created.

Just for the hell of it, let's try the threaded MPM and I'll try to sort
through its bugs to show mine.

Nevermind, it crashes before I have a chance.

[New Thread 30751 (LWP 28203)]
Delayed SIGSTOP caught for LWP 28203.
[New Thread 31776 (LWP 28204)]
Delayed SIGSTOP caught for LWP 28204.
Cannot find thread 33: invalid thread handle
(gdb)

Woot. Here's the backtrace for whoever's working on the threaded mpm..
dosen't look very useful though.

(gdb) bt
#0  0x401d6a21 in __linuxthreads_create_event () at events.c:26
#1  0x401d1110 in pthread_handle_create (thread=0x4064ac50,
attr=0x4064a9ac,
    start_routine=0x4003e904 <dummy_worker>, arg=0x811d554,
mask=0x819dc68,
    father_pid=28174, report_events=1, event_maskp=0x4064adac) at
manager.c:657
#2  0x401d09f5 in __pthread_manager (arg=0xe) at manager.c:167
#3  0x401d1509 in __pthread_manager_event (arg=0xe) at manager.c:231
(gdb)

In the 4-5 years I've been working with C/C++, I've never dealt with
anything this hosed. BTW - its dying when apache trys to find the handler
declared with 'SetHandler', since the first thing my module does is:

TWebSession WebSession = new TWebSession();
(which in turn has a bunch of other classes that it starts, including
TMySQLSet..)

I've also gotten the exact same results using threaded and non-threaded
mysql client libraries. Ugh.

Mabye I'm barking up the wrong tree?

My code (not MySQL's) uses malloc() and free() all over, it wasn't untill
I started filling in the blanks for the MySQL interfaces that this became
a problem. Any of the mysql code that uses malloc() is causing problems,
mysql_options(), mysql_connect(), etc. The only thing that I could
possibly think makes this apache's problem is the DSO interface and having
DSO's linked to external libraries. Problem is, 'WebSession' just loads a
shared object with dlopen() and runs a specified function from it
(passing the C++ class as a variable), and it does that fine w/o mysql.
It's purpose is to act as middleware between mysql, apache, and the
modules it houses. A simplified interface.

Also, I wanted to note that this is not a problem in apache 1.3, just 2.0.
The module I'm writing isin't expected to be in production for months, so
I figured writing for 2.0 now would make sense, versus having to rewrite
it again when 2.0 came out.

Oh well, back to pulling my hair out.

Justin

On Wed, 31 Oct 2001, Aaron Bannert wrote:

> On Wed, Oct 31, 2001 at 02:02:01PM -0600, Justin C. Darby wrote:
> > Configure line: ./configure --enable-ssl --enable-so --with-mpm=prefork
> > --enable-maintainer-mode
>
> Try this:
>
> CFLAGS="-Wall -g" CPPFLAGS="-Wall -g" ./configure --yourflags
>
> > --with-mpm=prefork because threaded seems to be a mess at the moment,
>
> <gratuitous plug>
> Have you tried the worker MPM? :)
> </gratuitous plug>
>
>
> Would you mind reposting the trace with the above CFLAGS/CPPFLAGS changes?
> (the full output is probably unnecessary)
>
> -aaron
>


Re: libmysqlclient and apache2

Posted by Aaron Bannert <aa...@clove.org>.
On Wed, Oct 31, 2001 at 02:02:01PM -0600, Justin C. Darby wrote:
> Configure line: ./configure --enable-ssl --enable-so --with-mpm=prefork
> --enable-maintainer-mode

Try this:

CFLAGS="-Wall -g" CPPFLAGS="-Wall -g" ./configure --yourflags

> --with-mpm=prefork because threaded seems to be a mess at the moment,

<gratuitous plug>
Have you tried the worker MPM? :)
</gratuitous plug>


Would you mind reposting the trace with the above CFLAGS/CPPFLAGS changes?
(the full output is probably unnecessary)

-aaron

Re: libmysqlclient and apache2

Posted by "Justin C. Darby" <wi...@kradaudio.net>.
On Wed, 31 Oct 2001, Aaron Bannert wrote:

> Apache also uses malloc() under the covers. Post a stack trace and we
> may be able to help.
>
> -aaron
>

I'll provide as much information about the install as I can.

Server info:

Configure line: ./configure --enable-ssl --enable-so --with-mpm=prefork
--enable-maintainer-mode

--with-mpm=prefork because threaded seems to be a mess at the moment,
--enable-maintainer-mode to (try to) build debugging data into httpd.

Server version string: Apache/2.0.27-dev (Unix) mod_ssl/3.0a0 OpenSSL/0.9.6

>From CVS, httpd-2.0 tree, October 22nd.

Same problem occurs with 2.0.26-dev snapshots.

Problem starts with #5 and goes up, the (!!) below is when I attempt to
hit the site with a web browser.. The same code snippits I'm using in the
TMySQLSet class work in other standalone applications with no visible
faults.

GDB output:
...
(gdb) set args -X
(gdb) exec httpd
(gdb) run
Starting program: /usr/local/apache2/bin/httpd -X
[New Thread 1024 (LWP 11156)]
(!!)
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 1024 (LWP 11156)]
chunk_alloc (ar_ptr=0x40313a00, nb=16) at malloc.c:2877
2877    malloc.c: No such file or directory.
        in malloc.c
(gdb) bt
#0  chunk_alloc (ar_ptr=0x40313a00, nb=16) at malloc.c:2877
#1  0x40261d3a in malloc_check (sz=11, caller=0x4033937e) at malloc.c:4645
#2  0x4025f06d in __libc_malloc (bytes=11) at malloc.c:2798
#3  0x4033937e in my_malloc (Size=11, MyFlags=16) at my_malloc.c:36
#4  0x4033958f in my_strdup (from=0x403278c0 "WebSession", MyFlags=16)
    at my_malloc.c:81
#5  0x40336a23 in mysql_options (mysql=0x40313a10,
    option=MYSQL_READ_DEFAULT_GROUP, arg=0x403278c0 "WebSession")
    at libmysql.c:2283
#6  0x403210a3 in TMySQLSet::Configure (this=0x8199578)
    at classtemplate/TMySQLSet.tmpl:26
#7  0x40320fe3 in TMySQLSet::TMySQLSet (this=0x8199578)
    at classtemplate/TMySQLSet.tmpl:7
#8  0x40321218 in TWebSession::TWebSession (this=0x81a0d98)
    at classtemplate/TWebSession.tmpl:7
#9  0x4032206b in websession_handler (r=0x81462ec) at main.cpp:145
#10 0x0809bef7 in ?? () at eval.c:41
#11 0x0809c67d in ?? () at eval.c:41
#12 0x08086758 in ?? () at eval.c:41
#13 0x0808144c in ?? () at eval.c:41
#14 0x080a8387 in ?? () at eval.c:41
#15 0x080a85d2 in ?? () at eval.c:41
#16 0x0809a6b2 in ?? () at eval.c:41
#17 0x0809a77c in ?? () at eval.c:41
#18 0x0809a8d7 in ?? () at eval.c:41
#19 0x0809adaa in ?? () at eval.c:41
#20 0x080a150b in ?? () at eval.c:41
#21 0x401fb627 in __libc_start_main (main=0x80a0edc, argc=2,
    ubp_av=0xbffffb24, init=0x80617f4, fini=0x80c0330,
    rtld_fini=0x4000dcd4 <_dl_fini>, stack_end=0xbffffb1c)
    at ../sysdeps/generic/libc-start.c:129
(gdb) bt full
#0  chunk_alloc (ar_ptr=0x40313a00, nb=16) at malloc.c:2877
        victim = 0x0
        victim_size = 16
        idx = 2
        bin = 0x40313a00
        remainder = 0xbfffd6c8
        remainder_size = 2
        remainder_index = 1076967952
        block = 1077222432
        startidx = 5
        fwd = 0x40313a10
        bck = 0x5
        q = 0x40313a10
        victim_size = 16
        idx = 2
        remainder = 0xbfffd6c8
        remainder_index = 1076967952
        block = 1077222432
#1  0x40261d3a in malloc_check (sz=11, caller=0x4033937e) at malloc.c:4645
        victim = 0x10
        nb = 16
#2  0x4025f06d in __libc_malloc (bytes=11) at malloc.c:2798
        result = (void *) 0x40313a00
        bytes = 1076967952
        ar_ptr = (arena *) 0x40313a10
        nb = 3221215064
        victim = 0x5
        hook = (void *(*)()) 0x40313a00 <main_arena>
        nb = 3221215064
#3  0x4033937e in my_malloc (Size=11, MyFlags=16) at my_malloc.c:36
        point = 0x4 <Address 0x4 out of bounds>
        _db_func_ = 0x4034ac0f "mysql_option"
        _db_file_ = 0x4034a488 "libmysql.c"
        _db_level_ = 2
        _db_framep_ = (char **) 0x403494a0
#4  0x4033958f in my_strdup (from=0x403278c0 "WebSession", MyFlags=16)
    at my_malloc.c:81
        ptr = 0x4034ac0f "mysql_option"
        length = 11
#5  0x40336a23 in mysql_options (mysql=0x40313a10,
    option=MYSQL_READ_DEFAULT_GROUP, arg=0x403278c0 "WebSession")
    at libmysql.c:2283
        mysql = (MYSQL *) 0x40313a10
        option = MYSQL_READ_DEFAULT_GROUP
        _db_func_ = 0x4034dee5 "?func"
        _db_file_ = 0x4034deeb "?file"
        _db_level_ = 1
        _db_framep_ = (char **) 0xbfffd7d8
#6  0x403210a3 in TMySQLSet::Configure (this=0x8199578)
    at classtemplate/TMySQLSet.tmpl:26
        this = (TMySQLSet *) 0x8199578
#7  0x40320fe3 in TMySQLSet::TMySQLSet (this=0x8199578)
    at classtemplate/TMySQLSet.tmpl:7
        this = (TMySQLSet *) 0x8199578
#8  0x40321218 in TWebSession::TWebSession (this=0x81a0d98)
    at classtemplate/TWebSession.tmpl:7
No locals.
#9  0x4032206b in websession_handler (r=0x81462ec) at main.cpp:145
        WebSession = (TWebSession *) 0x80d8cb4
        bapasswd = 0x80d8cb4 "D\231\r\b"
        type = 0x80d8cb4 "D\231\r\b"
        data = 0x40016b4c ""
        rc = 0
        child = (int (*)()) 0x8144a3c
        handle = (void *) 0x808e7ad
        error = 0xbfffd888 "\t\bb\024\bLk\001@\234\t\b\224d\024\bj\024\b\t"
#10 0x0809bef7 in ?? () at eval.c:41
        ap = (void **) 0xbffffb24
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        p = 0x40016b4c ""
        result = 3221224228
        result = 1073834828
#11 0x0809c67d in ?? () at eval.c:41
        ap = (void **) 0xbffffb24
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        p = 0x40016b4c ""
        result = 3221224228
        result = 1073834828
#12 0x08086758 in ?? () at eval.c:41
        ap = (void **) 0xbffffb24
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        p = 0x40016b4c ""
        result = 3221224228
        result = 1073834828
#13 0x0808144c in ?? () at eval.c:41
        ap = (void **) 0xbffffb24
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        p = 0x40016b4c ""
        result = 3221224228
        result = 1073834828
#14 0x080a8387 in ?? () at eval.c:41
        ap = (void **) 0xbffffb24
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        p = 0x40016b4c ""
        result = 3221224228
        result = 1073834828
#15 0x080a85d2 in ?? () at eval.c:41
        ap = (void **) 0xbffffb24
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        p = 0x40016b4c ""
        result = 3221224228
        result = 1073834828
#16 0x0809a6b2 in ?? () at eval.c:41
        ap = (void **) 0xbffffb24
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        p = 0x40016b4c ""
        result = 3221224228
        result = 1073834828
#17 0x0809a77c in ?? () at eval.c:41
        ap = (void **) 0xbffffb24
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        p = 0x40016b4c ""
        result = 3221224228
        result = 1073834828
#18 0x0809a8d7 in ?? () at eval.c:41
        ap = (void **) 0xbffffb24
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        p = 0x40016b4c ""
        result = 3221224228
        result = 1073834828
#19 0x0809adaa in ?? () at eval.c:41
        ap = (void **) 0xbffffb24
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        p = 0x40016b4c ""
        result = 3221224228
        result = 1073834828
#20 0x080a150b in ?? () at eval.c:41
        ap = (void **) 0xbffffb24
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        digval = 1076967936
        p = 0x40016b4c ""
        result = 3221224228
        result = 1073834828
#21 0x401fb627 in __libc_start_main (main=0x80a0edc, argc=2,
    ubp_av=0xbffffb24, init=0x80617f4, fini=0x80c0330,
    rtld_fini=0x4000dcd4 <_dl_fini>, stack_end=0xbffffb1c)
    at ../sysdeps/generic/libc-start.c:129
        ubp_av = (char **) 0xbffffb24
        fini = (void (*)()) 0x40016b4c <_dl_debug_mask>
        rtld_fini = (void (*)()) 0x2 <__strtol_internal+2>
        ubp_ev = (char **) 0xbffffb30
(gdb)



Re: libmysqlclient and apache2

Posted by Aaron Bannert <aa...@clove.org>.
On Wed, Oct 31, 2001 at 01:30:54PM -0600, Justin C. Darby wrote:
> I'm writing a C++ apache module for httpd-2.0, and I'm running into a bit
> of a wall with Apache's memory allocation system.
> 
> It appears that whenever the mysql client library tries to malloc()
> memory, it causes the server to crash.
> 
> When I call mysql_options(), it's crashing in the call to my_malloc(), in
> mysys/my_malloc.c, line 36 (mysql 2.23.43). It's a perfectly harmless
> malloc() call, done in a thread-safe build of the mysql client library
> (which is why I'm blaming Apache before MySQL here..).
> 
> Over-detailed bloated gdb/strace/etc available if needed, however, I was
> able to reproduce this on every assorted linux box in my office.

Apache also uses malloc() under the covers. Post a stack trace and we
may be able to help.

-aaron