#118 Segmentation fault in MATCH AGAINST queries

MySQLdb-1.1
closed
Andy Dustman
MySQLdb (285)
5
2012-09-19
2005-01-05
Eugene Bond
No

MySQLdb: 1.1.7, 1.1.8
MySQL: 4.1.7
System: FreeBSD

In queries "SELECT blabla, MATCH foo AGAINST ('bar') AS
rel FROM table..." I got "Segmentation fault" and
process stoped..
All other SELECTs, INSERTs, etc works fine.

Discussion

  • Andy Dustman
    Andy Dustman
    2005-01-05

    Logged In: YES
    user_id=71372

    It's not clear from your comments whether the client or the
    server is crashing. If it's the server, there's not much I
    can do about this, although I will note that the current
    version is 4.1.8.

     
  • Eugene Bond
    Eugene Bond
    2005-01-05

    Logged In: YES
    user_id=1190738

    No, this SQL is just for example. Full sintax is correct and
    works from console and phpMyAdmin.

    "SELECT id, text, MATCH text AGAINST ('%s') AS rel FROM
    texttable HAVING rel > 20 ORDER BY rel DESC"

    Segmantation fault comes from client. And program is
    aborted. There is no debug-backtrace but if I set comment on
    query-line - programm not crash.

     
  • Andy Dustman
    Andy Dustman
    2005-01-05

    Logged In: YES
    user_id=71372

    I can't do much without a backtrace.

    $ gdb python
    (gdb) run yourscript.py
    <crash>
    (gdb) bt

    Post the output of bt here.

     
  • Eugene Bond
    Eugene Bond
    2005-01-06

    Logged In: YES
    user_id=1190738

    Here is bt, but my dummy eyes don't see any helfull info..


    Program received signal SIGSEGV, Segmentation fault.
    0x80b0e17 in Py_InitModule4 ()
    (gdb) bt

    0 0x80b0e17 in Py_InitModule4 ()

    1 0x80b0bb0 in Py_InitModule4 ()

    2 0x80b0c8e in Py_InitModule4 ()

    3 0x80b0f3c in Py_VaBuildValue ()

    4 0x80b0ed1 in Py_BuildValue ()

    5 0x2836adad in _mysql_ResultObject_describe () from

    /usr/local/lib/python2.4/site-packages/_mysql.so

    6 0x80ce274 in PyCFunction_Call ()

    7 0x8099e44 in PyEval_GetFuncDesc ()

    8 0x8097fc3 in PyEval_EvalFrame ()

    9 0x8099fd3 in PyEval_GetFuncDesc ()

    10 0x8099ec9 in PyEval_GetFuncDesc ()

    11 0x8097fc3 in PyEval_EvalFrame ()

    12 0x8099fd3 in PyEval_GetFuncDesc ()

    13 0x8099ec9 in PyEval_GetFuncDesc ()

    14 0x8097fc3 in PyEval_EvalFrame ()

    15 0x8099fd3 in PyEval_GetFuncDesc ()

    16 0x8099ec9 in PyEval_GetFuncDesc ()

    17 0x8097fc3 in PyEval_EvalFrame ()

    18 0x8098e40 in PyEval_EvalCodeEx ()

    19 0x809a038 in PyEval_GetFuncDesc ()

    20 0x8099ec9 in PyEval_GetFuncDesc ()

    21 0x8097fc3 in PyEval_EvalFrame ()

    22 0x8099fd3 in PyEval_GetFuncDesc ()

    23 0x8099ec9 in PyEval_GetFuncDesc ()

    24 0x8097fc3 in PyEval_EvalFrame ()

    25 0x8099fd3 in PyEval_GetFuncDesc ()

    26 0x8099ec9 in PyEval_GetFuncDesc ()

    27 0x8097fc3 in PyEval_EvalFrame ()

    28 0x8098e40 in PyEval_EvalCodeEx ()

    29 0x809a038 in PyEval_GetFuncDesc ()

    30 0x8099ec9 in PyEval_GetFuncDesc ()

    31 0x8097fc3 in PyEval_EvalFrame ()

    32 0x8099fd3 in PyEval_GetFuncDesc ()

    33 0x8099ec9 in PyEval_GetFuncDesc ()

    34 0x8097fc3 in PyEval_EvalFrame ()

    35 0x8098e40 in PyEval_EvalCodeEx ()

    36 0x809a038 in PyEval_GetFuncDesc ()

    37 0x8099ec9 in PyEval_GetFuncDesc ()

    38 0x8097fc3 in PyEval_EvalFrame ()

    39 0x8099fd3 in PyEval_GetFuncDesc ()

    40 0x8099ec9 in PyEval_GetFuncDesc ()

    41 0x8097fc3 in PyEval_EvalFrame ()

    42 0x8099fd3 in PyEval_GetFuncDesc ()

    43 0x8099ec9 in PyEval_GetFuncDesc ()

    44 0x8097fc3 in PyEval_EvalFrame ()

    45 0x8099fd3 in PyEval_GetFuncDesc ()

    46 0x8099ec9 in PyEval_GetFuncDesc ()

    47 0x8097fc3 in PyEval_EvalFrame ()

    48 0x8098e40 in PyEval_EvalCodeEx ()

    49 0x80cdd1a in PyFunction_SetClosure ()

    50 0x8059a08 in PyObject_Call ()

    ---Type <return> to continue, or q <return> to quit---

    51 0x809a48e in PyEval_GetFuncDesc ()

    52 0x8098081 in PyEval_EvalFrame ()

    53 0x8098e40 in PyEval_EvalCodeEx ()

    54 0x80cdd1a in PyFunction_SetClosure ()

    55 0x8059a08 in PyObject_Call ()

    56 0x809a48e in PyEval_GetFuncDesc ()

    57 0x8098081 in PyEval_EvalFrame ()

    58 0x8098e40 in PyEval_EvalCodeEx ()

    59 0x80cdd1a in PyFunction_SetClosure ()

    60 0x8059a08 in PyObject_Call ()

    61 0x809a48e in PyEval_GetFuncDesc ()

    62 0x8098081 in PyEval_EvalFrame ()

    63 0x8098e40 in PyEval_EvalCodeEx ()

    64 0x809a038 in PyEval_GetFuncDesc ()

    65 0x8099ec9 in PyEval_GetFuncDesc ()

    66 0x8097fc3 in PyEval_EvalFrame ()

    67 0x8098e40 in PyEval_EvalCodeEx ()

    68 0x809a038 in PyEval_GetFuncDesc ()

    69 0x8099ec9 in PyEval_GetFuncDesc ()

    70 0x8097fc3 in PyEval_EvalFrame ()

    71 0x8099fd3 in PyEval_GetFuncDesc ()

    72 0x8099ec9 in PyEval_GetFuncDesc ()

    73 0x8097fc3 in PyEval_EvalFrame ()

    74 0x8098e40 in PyEval_EvalCodeEx ()

    75 0x809a038 in PyEval_GetFuncDesc ()

    76 0x8099ec9 in PyEval_GetFuncDesc ()

    77 0x8097fc3 in PyEval_EvalFrame ()

    78 0x8098e40 in PyEval_EvalCodeEx ()

    79 0x8095c49 in PyEval_EvalCode ()

    80 0x80b3933 in PyRun_FileExFlags ()

    81 0x80b38ee in PyRun_FileExFlags ()

    82 0x80b38c4 in PyRun_FileExFlags ()

    83 0x80b2c0f in PyRun_SimpleFileExFlags ()

    84 0x80b26c0 in PyRun_AnyFileExFlags ()

    85 0x8054d5f in Py_Main ()

    86 0x805445d in main ()

    87 0x805438e in _start ()

     
  • Andy Dustman
    Andy Dustman
    2005-01-06

    Logged In: YES
    user_id=71372

    5 0x2836adad in _mysql_ResultObject_describe () from

    /usr/local/lib/python2.4/site-packages/_mysql.so

    That's the culprit. Something in your result set makes it
    unhappy.

        t = Py_BuildValue("(siiiiii)",
                  fields[i].name,
                  (long) fields[i].type,
                  (long) fields[i].max_length,
                  (long) fields[i].length,
                  (long) fields[i].length,
                  (long) fields[i].decimals,
                  (long) !(IS_NOT_NULL(fields[i].flags)));
    

    And the only thing possible that I can see is
    fields[i].name, since it is a string. Perhaps it's getting a
    NULL pointer back from MySQL?

    You are renaming your MATCH expression to rel, which should
    not be a problem.

    Try adding to setup.py (in the section for your platform)
    something like this:

    extra_compile_args.append("-g")
    

    This should add some debugging information, which will give
    a better backtrace. Then rebuild and try again. You should
    also be able to do this:

    (gdb) frame 4 # assuming it dies the same way
    (gdb) print i,fields[i]

     
  • Eugene Bond
    Eugene Bond
    2005-01-11

    Logged In: YES
    user_id=1190738

    I'll try it in next few days and report ASAP

     
  • Eugene Bond
    Eugene Bond
    2005-01-17

    Logged In: YES
    user_id=1190738

    Crashed on start with error:

    File
    "/usr/local/lib/python2.4/site-packages/MySQLdb/init.py",
    line 27, in ?
    import _mysql
    ImportError:
    /usr/local/lib/python2.4/site-packages/_mysql.so: Undefined
    symbol "mysql_rollback"
    (no debugging symbols found)...
    Program exited with code 01.

     
  • Eugene Bond
    Eugene Bond
    2005-01-17

    Logged In: YES
    user_id=1190738

    With MySQLdb v.1.0.1 it crach like old times and I got this
    debug info:

    (gdb) frame 5

    5 0x2836add5 in _mysql_ResultObject_describe

    (self=0x8400d24, args=0x811f02c) at _mysql.c:923
    923 t = Py_BuildValue("(siiiiii)",
    (gdb) print i,fields[i]
    $1 = {name = 0x837622c "", org_name = 0x131 <Error reading="" address="" 0x131:="" Bad="" address="">, table = 0x0,
    org_table = 0x8376178 "", db = 0x2607 <Error reading="" address="" 0x2607:="" Bad="" address="">, catalog = 0x0,
    def = 0x8376100 "", length = 224, max_length = 0,
    name_length = 137847712, org_name_length = 305,
    table_length = 0, org_table_length = 137847580, db_length
    = 305, catalog_length = 0, def_length = 138555056,
    flags = 171, decimals = 0, charsetnr = 136315700, type = 305}

     
  • Andy Dustman
    Andy Dustman
    2005-01-21

    Logged In: YES
    user_id=71372

    I'll have to see if I can reproduce this, I guess.
    Something defintely looks screwy, but I still tend to think
    it's MySQL. 4.1.9 is out now.

    I wonder if mysql_fetch_fields() could be returning a NULL
    pointer. print fields in gdb should show if that is what is
    happening. The documentation does not say that can happen.

    http://dev.mysql.com/doc/mysql/en/mysql_fetch_fields.html

    You might also examine the value of n in that stack frame,
    which is the number of fields. Also d is the description
    tuple (return value).

     
  • Andy Dustman
    Andy Dustman
    2005-01-23

    Logged In: YES
    user_id=71372

    OK, here's my slightly cheesy test program:

    !/usr/bin/python

    schema = """
    CREATE TABLE my_fs (
    id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
    path VARCHAR(255) NOT NULL,
    contents TEXT NOT NULL,
    FULLTEXT (path,contents)
    )"""

    def create(c, dummy):
    c.execute(schema)

    def index(c, path):
    import os.path
    if os.path.isfile(path):
    contents = open(path).read()
    c.execute("""INSERT INTO my_fs (path, contents)
    VALUES (%s,%s)""",
    (path, contents))
    elif os.path.isdir(path):
    for file in [ os.path.join(path, f) for f in
    os.listdir(path) ]
    :
    index(c, file)

    def find(c, what):
    c.execute("""SELECT path, MATCH (path, contents) AGAINST
    (%s) AS rel
    FROM my_fs
    WHERE MATCH (path, contents) AGAINST (%s)
    LIMIT 10""", (what,what))
    for path, rel in c:
    print path, rel

    if name == "main":
    import sys, MySQLdb
    db =
    MySQLdb.connect(db='test',read_default_file="~/.my.cnf")
    c = db.cursor()
    f = globals()[sys.argv[1]]
    f(c, sys.argv[2])

    Results:

    andy@tweek MySQLdb $ python fulltexttest.py create nothin
    andy@tweek MySQLdb $ python fulltexttest.py index .
    andy@tweek MySQLdb $ python fulltexttest.py find Cursor
    ./regress3.py~ 1.0185829401
    ./regress3.py 1.016715765
    ./regress2.py 0.944855749607
    ./MySQLdb/cursors.pyc 0.809565961361
    ./doc/public/trees.html 0.777606010437
    ./build/lib.linux-i686-2.3/MySQLdb/connections.py 0.730027079582
    ./MySQLdb/connections.py 0.728077411652
    ./build/lib.linux-i686-2.4/MySQLdb/connections.py 0.706077456474
    ./build/lib.linux-i686-2.3/MySQLdb/cursors.py 0.692252576351
    ./MySQLdb/cursors.py 0.689828455448

    Test performed on Linux on i386, MySQL-4.1.8.

    In other words, I can't reproduce the problem.

     
  • Andy Dustman
    Andy Dustman
    2005-01-23

    Logged In: YES
    user_id=71372

    Additionally, I am using Python 2.4 and the CVS MySQLdb (but
    not significantly different from 1.1.9).

     
  • Eugene Bond
    Eugene Bond
    2005-01-25

    Logged In: YES
    user_id=1190738

    Your test produce same results:

    1. on running with params create and index it gives:
      Exception exceptions.AttributeError: "'Connection' object
      has no attribute 'next_result'" in <bound method="" Cursor.__del__="" of="" <MySQLdb.cursors.Cursor="" object="" at="" 0x81cce2c="">> ignored

    2. on running with param find drops down with:
      Segmentation fault (core dumped)

    Table my_fs contains all data.. Manual executing of query
    works and returns right results..

     
  • Eugene Bond
    Eugene Bond
    2005-02-15

    Logged In: YES
    user_id=1190738

    I have installed ver 1.2 and looks like there is no more
    problem.

    Thanks

     
  • Eugene Bond
    Eugene Bond
    2005-02-15

    Logged In: YES
    user_id=1190738

    This has already been fixed in the most recent release; please
    upgrade.