Bug #308 mysql 3.23.56 segfaults under slackware source install
Submitted: 18 Apr 2003 15:22 Modified: 22 Apr 2003 10:28
Reporter: Jerry Bonner Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:3.23.56 OS:Linux (slackware 8)
Assigned to: CPU Architecture:Any

[18 Apr 2003 15:22] Jerry Bonner
Description:
I have installed slackware from source, when compiling mysql with static libraries, threads will segfault when network connections are attempted.

output :

root@spongebob:/usr/src/mysql-3.23.56# safe_mysqld --user=mysql
Starting mysqld daemon with databases from /usr/local/mysql/var
/usr/local/mysql/bin/safe_mysqld: line 284: 22268 Segmentation fault      $NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-locking >>$err_log 2>&1

Number of processes running now: 1
mysqld process hanging, pid 22271 - killed
030418 16:01:50  mysqld restarted
/usr/local/mysql/bin/safe_mysqld: line 284: 22291 Segmentation fault      $NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-locking >>$err_log 2>&1

Number of processes running now: 1
mysqld process hanging, pid 22294 - killed
030418 16:02:00  mysqld restarted

this is after trying two connections from the local network.

gdb out :[New Thread 22329 (manager thread)]
[New Thread 22328 (initial thread)]
[New Thread 22330]
/usr/local/mysql/libexec/mysqld: ready for connections
[New Thread 22331]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 22331]
0x40002518 in ?? ()
(gdb) backtrace full
#0  0x40002518 in ?? ()
No symbol table info available.
#1  0x827bae6 in __gethostbyaddr_r (addr=0x83e1430, len=4, type=2, resbuf=0x837314c, buffer=0x83e3480 "Ñ\027¿&\bZ5\bdate_pri\2004>\b",
    buflen=1024, result=0xbf5ff96c, h_errnop=0xbf5ff970) at ../nss/getXXbyYY_r.c:200
        startp = (service_user *) 0x83d2a78
        start_fct = 0x4417d050
        nip = (service_user *) 0x83d2aa8
        fct = 0x40002430
        no_more = -1084296092
        status = 1073758464
        nscd_status = 1
#2  0x827b89b in gethostbyaddr (addr=0x83e1430, len=4, type=2) at ../nss/getXXbyYY.c:145
        buffer_size = 1024
        resbuf = {h_name = 0x83e34a6 ".\n", h_aliases = 0x83e34c4, h_addrtype = 2, h_length = 4, h_addr_list = 0x83e3490}
        result = (struct hostent *) 0x0
        save = 138229856
        h_errno_tmp = 1
#3  0x8070304 in ip_to_hostname ()
No symbol table info available.
#4  0x8070bcc in check_connections ()
No symbol table info available.
#5  0x8070fca in handle_one_connection ()
No symbol table info available.
#6  0x82415e6 in pthread_start_thread (arg=0xbf5ffc00) at manager.c:291
        self = 0xbf5ffc00
        request = {req_thread = 0xbf5ffc00, req_kind = REQ_DEBUG, req_args = {create = {attr = 0x0, fn = 0, arg = 0x0, mask = {__val = {
          0 <repeats 32 times>}}}, free = {thread_id = 0}, exit = {code = 0}, post = 0x0, for_each = {fn = 0, arg = 0x0}}}
        outcome = (void *) 0x1
(gdb)

other info :

glibc 2.2.5
gcc 2.95.3
gdb 5.0

mysqlbug out :

SEND-PR: -*- send-pr -*-
SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
SEND-PR: will all comments (text enclosed in `<' and `>').
SEND-PR:
From: bonnej
To: mysql@lists.mysql.com
Subject: [50 character or so descriptive subject here (for reference)]

>Description:
        <precise description of the problem (multiple lines)>
>How-To-Repeat:
        <code/input/activities to reproduce the problem (multiple lines)>
>Fix:
        <how to correct or work around the problem, if known (multiple lines)>

>Submitter-Id:  <submitter ID>
>Originator:
>Organization:
 <organization of PR author (multiple lines)>
>MySQL support: [none | licence | email support | extended email support ]
>Synopsis:      <synopsis of the problem (one line)>
>Severity:      <[ non-critical | serious | critical ] (one line)>
>Priority:      <[ low | medium | high ] (one line)>
>Category:      mysql
>Class:         <[ sw-bug | doc-bug | change-request | support ] (one line)>
>Release:       mysql-3.23.56 (Source distribution)

>Environment:
        <machine, os, target, libraries (multiple lines)>
System: Linux spongebob 2.4.20 #2 SMP Fri Jan 17 16:44:25 CST 2003 i686 unknown
Architecture: i686

Some paths:  /usr/local/bin/perl /usr/bin/make /usr/bin/gmake /usr/bin/gcc /usr/bin/cc
GCC: Reading specs from /usr/lib/gcc-lib/i386-slackware-linux/2.95.3/specs
gcc version 2.95.3 20010315 (release)
Compilation info: CC='gcc'  CFLAGS='-O2 -mcpu=pentiumpro'  CXX='gcc'  CXXFLAGS='-O2 -mcpu=pentiumpro -felide-constructors'  LDFLAGS=''
LIBC:
lrwxrwxrwx    1 root     root           13 Apr  4 11:34 /lib/libc.so.6 -> libc-2.3.1.so
-rwxr-xr-x    1 root     root      4783716 May 25  2001 /lib/libc-2.2.3.so
-rwxr-xr-x    1 root     root      1237848 May 17  2002 /lib/libc-2.2.5.so
-rwxr-xr-x    1 root     root      1435624 Mar  4 23:57 /lib/libc-2.3.1.so
-rw-r--r--    1 root     root     24984184 Jul 30  2002 /usr/lib/libc.a
-rw-r--r--    1 root     root          178 Jul 30  2002 /usr/lib/libc.so
Configure command: ./configure '--prefix=/usr/local/mysql' '--with-extra-charsets=complex' '--enable-thread-safe-client' '--enable-local-infile' '--enable-assembler' '--disable-shared' '--with-client-ldflags=-all-static' '--with-mysqld-ldflags=-all-static' '--without-bench' '--with
out-docs' '--without-debug' '--sysconfdir=/etc' '--with-innodb' '--with-unix-socket-path=/var/run/mysqld.sock' '--with-mysqld-user=mysql' 'CF
LAGS=-O2 -mcpu=pentiumpro' 'CXXFLAGS=-O2 -mcpu=pentiumpro -felide-constructors' 'CXX=gcc'

I have tried this on two separate slackware systems with updated glibc packages.

heres a gdb session --with-debug : 

(gdb) backtrace full
#0  0x40002518 in ?? ()
No symbol table info available.
#1  0x829b4b6 in __gethostbyaddr_r (addr=0x840b0d8, len=4, type=2, resbuf=0x839c24c, buffer=0x840d1a0 "Ñ\027¿&Hå7\b", buflen=1024,
    result=0xbf5ff95c, h_errnop=0xbf5ff960) at ../nss/getXXbyYY_r.c:200
        startp = (service_user *) 0x83fc010
        start_fct = 0x4417d050
        nip = (service_user *) 0x83fc040
        fct = 0x40002430
        no_more = -1084296108
        status = 1073758464
        nscd_status = 1
#2  0x829b26b in gethostbyaddr (addr=0x840b0d8, len=4, type=2) at ../nss/getXXbyYY.c:145
        buffer_size = 1024
        resbuf = {h_name = 0x840d1c6 ".\n", h_aliases = 0x840d1e4, h_addrtype = 2, h_length = 4, h_addr_list = 0x840d1b0}
        result = (struct hostent *) 0x0
        save = 138399384
        h_errno_tmp = 1
#3  0x8072cb5 in ip_to_hostname (in=0x840b0d8, errors=0xbf5ff9fc) at hostname.cc:192
        i = 26
        _db_func_ = 0x840aca0 "0º8\b4º8\b\200x8\b ´@\b\013"
        _db_file_ = 0x4 <Address 0x4 out of bounds>
        _db_level_ = 3210738276
        _db_framep_ = (char **) 0x840acac
        hp = (hostent *) 0x1
        check = (hostent *) 0x0
        name = 0x83fce98 "\200"
#4  0x807390d in check_connections (thd=0x840aca0) at sql_parse.cc:346
        ip = "209.23.180.12\000\000\000\224ú_¿ÜW%\b\000\000\000\000´ú"
        thd = (THD *) 0x840aca0
        connect_errors = 0
        net = (NET *) 0x840acac
        pkt_len = 1
        user = 0x840acac " ´@\b\013"
        passwd = 0x840b0d8 "Ñ\027´\f"
        db = 0x1a <Address 0x1a out of bounds>
#5  0x8073dc9 in handle_one_connection (arg=0x840aca0) at sql_parse.cc:534
        error = 1
        net = (NET *) 0x840acac
        arg = (void *) 0x1
        thd = (THD *) 0x840aca0
        set = {__val = {0 <repeats 32 times>}}
#6  0x8260e46 in pthread_start_thread (arg=0xbf5ffc00) at manager.c:291
        self = 0xbf5ffc00
        request = {req_thread = 0xbf5ffc00, req_kind = REQ_DEBUG, req_args = {create = {attr = 0x0, fn = 0, arg = 0x0, mask = {__val = {
          0 <repeats 32 times>}}}, free = {thread_id = 0}, exit = {code = 0}, post = 0x0, for_each = {fn = 0, arg = 0x0}}}
---Type <return> to continue, or q <return> to quit---
        outcome = (void *) 0x1

How to repeat:
segfaulting child happens everytime a network connection is made via "mysql" :

root@sql# mysql -u asdfsa -p -h spongebob
Enter password:
ERROR 2013: Lost connection to MySQL server during query

server spits out :

Number of processes running now: 1
mysqld process hanging, pid 22271 - killed
030418 16:01:50  mysqld restarted
/usr/local/mysql/bin/safe_mysqld: line 284: 22291 Segmentation fault      $NOHUP_NICENESS $ledir/$MYSQLD $defaults --basedir=$MY_BASEDIR_VERSION --datadir=$DATADIR $USER_OPTION --pid-file=$pid_file --skip-locking >>$err_log 2>&1

Suggested fix:
configuring without static seems to make a fully functional binary.
[22 Apr 2003 10:28] Michael Widenius
This looks like the too small stack problem bug we fixed in MySQL 4.0 recently.

This problems happens when you have a glibc library where host resolving uses a LOT of stack space (which is not a good idea in a threaded environment).

Fix:  Get and install the latest MySQL 4.0 source and start mysqld with --thread_stack=1M