Reading fields can sometimes lead to an IndexError

Bug #592073 reported by Geert JM Vanderkelen
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
MySQL Connector/Python
Confirmed
Medium
Geert JM Vanderkelen

Bug Description

Got it reproduced in an app, but trying to make a smaller test case it works OK..

None: 03 d e f 00 06 T A B L E S 00 0a T A B L E _ N A M E 0a T A B L E _ N A M E 0c ! 00 c0 00 00 00 fd 01 00 00 00 00
None: 03 d e f 00 06 T A B L E S 00 0c T A B L E _ S C H E M A 0c T A B L E _ S C H E M A 0c ! 00 c0 00 00 00 fd 01 00 00 00 00
None: fe 00 00 20 00
Traceback (most recent call last):
  File "prodemot.py", line 78, in <module>
    main()
  File "prodemot.py", line 72, in main
    test_demotion_int(master,slave)
  File "prodemot.py", line 56, in test_demotion_int
    wait_table_exists(slave, table='t1', db='test')
  File "prodemot.py", line 42, in wait_table_exists
    slave.table_exists(table,db)
  File "prodemot.py", line 30, in table_exists
    cur.execute(sql, dict(tbl=tableName,db=dbName))
  File "/Users/geert/Projects/myconnpy/0.2/myconnpy-dev/python2/mysql/connector/cursor.py", line 310, in execute
    res = self.db().protocol.cmd_query(stmt)
  File "/Users/geert/Projects/myconnpy/0.2/myconnpy-dev/python2/mysql/connector/protocol.py", line 136, in deco
    return func(*args, **kwargs)
  File "/Users/geert/Projects/myconnpy/0.2/myconnpy-dev/python2/mysql/connector/protocol.py", line 475, in cmd_query
    return self.handle_cmd_result(self._recv_packet())
  File "/Users/geert/Projects/myconnpy/0.2/myconnpy-dev/python2/mysql/connector/protocol.py", line 459, in handle_cmd_result
    return self._handle_resultset(buf)[0:2]
  File "/Users/geert/Projects/myconnpy/0.2/myconnpy-dev/python2/mysql/connector/protocol.py", line 62, in call
    return func(*args, **kwargs)
  File "/Users/geert/Projects/myconnpy/0.2/myconnpy-dev/python2/mysql/connector/protocol.py", line 126, in call
    return func(*args,**kwargs)
  File "/Users/geert/Projects/myconnpy/0.2/myconnpy-dev/python2/mysql/connector/protocol.py", line 415, in _handle_resultset
    fields.append(self._pkt_parse_field(buf))
  File "/Users/geert/Projects/myconnpy/0.2/myconnpy-dev/python2/mysql/connector/protocol.py", line 126, in call
    return func(*args,**kwargs)
  File "/Users/geert/Projects/myconnpy/0.2/myconnpy-dev/python2/mysql/connector/protocol.py", line 301, in _pkt_parse_field
    (buf,field['db']) = utils.read_lc_string(buf)
  File "python2/mysql/connector/utils.py", line 156, in read_lc_string
mysql.connector.errors.InterfaceError: Failed executing the operation; string index out of range

Tags: protocol
Revision history for this message
Ned Rockson (nedrocks) wrote :

This bug is affecting us intermittently. We haven't yet gotten to the bottom of it but I wrapped the buffer read in protocol._handle_resultset in a try/except IndexError to print out the number of fields it is expecting:

(approx line 407 on build 292)
            buf = self.conn.recv()
            try:
              fields.append(self._pkt_parse_field(buf))
            except IndexError:
              data = dict(i=i, nrflds=nrflds, buf=buf)
              import sys
              print >> sys.stderr, 'Failed reading packet, data: %s' % data
              raise

Checking the output, the nrflds varies but is most consistently 131072. This led me to believe this was related to a thread stack overflow but again this is not confirmed. Other values that have been returned:

24
535
626
795
1211
1347

I am using python 2.6.5 on ubuntu 10.04 64-bit and Percona patched Mysql 5.1.54.

Also note that the error isn't thrown in the exact same place. For me stack is:

http://pastie.org/2994223

Revision history for this message
matburt (bsdmatburt) wrote :

I get this every time I try to insert into a table. I will have to replace this library in my code now. June 2010 and still no solution?

mysql_connector_python-0.3.2_devel-py2.7.egg
CentOS 5.7
MySQL 5.5

    cur.execute("INSERT INTO test (severity, eventtime, hostname, service, version, message, sourceLocation) values ('" + severity + "', 'NOW()', '" + host + "', '" + service + "', '0.0', '" + message + "', 'none')")
  File "build/bdist.linux-x86_64/egg/mysql/connector/cursor.py", line 314, in execute
  File "build/bdist.linux-x86_64/egg/mysql/connector/protocol.py", line 136, in deco
  File "build/bdist.linux-x86_64/egg/mysql/connector/protocol.py", line 479, in cmd_query
  File "build/bdist.linux-x86_64/egg/mysql/connector/protocol.py", line 463, in handle_cmd_result
  File "build/bdist.linux-x86_64/egg/mysql/connector/protocol.py", line 62, in call
  File "build/bdist.linux-x86_64/egg/mysql/connector/protocol.py", line 126, in call
  File "build/bdist.linux-x86_64/egg/mysql/connector/protocol.py", line 408, in _handle_resultset
  File "build/bdist.linux-x86_64/egg/mysql/connector/protocol.py", line 126, in call
  File "build/bdist.linux-x86_64/egg/mysql/connector/protocol.py", line 292, in _pkt_parse_field
  File "build/bdist.linux-x86_64/egg/mysql/connector/utils.py", line 170, in read_lc_string
mysql.connector.errors.InterfaceError: Failed executing the operation; string index out of range

Revision history for this message
Ned Rockson (nedrocks) wrote :

Matburt - I discovered our issue was due to a application level timeout. We pooled our connections but would timeout queries after x seconds. If we then used that connection again it had stale state built up. Thus, you might not be fully flushing out your connections before the next use. Although this error is quite vexing I don't believe it's a library error.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.