Connection.is_connected raises BrokenPipe error after connection lost

Bug #918118 reported by Sunfox on 2012-01-18
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MySQL Connector/Python
In Progress
Undecided
Unassigned

Bug Description

python -c "import mysql.connector as db; print db.__version__"
(0, 3, 2, 'devel', 292)

python --version
Python 2.6.5

mysql -NB -e "SELECT VERSION()"
5.5.17-55-log (using percona server)

uname -a
Linux sunfox 2.6.32-36-server #79-Ubuntu SMP Tue Nov 8 22:44:38 UTC 2011 x86_64 GNU/Linux

I lost my traceback so I cannot attach, but problem is, is_connected function trying to send data to closed socket i think. BrokenPipe error probably occured because I connect to localhost and myconnpy uses mysql socket.

FYI, the code for is_conntected() and ping() has been refactored a bit in later versions.

I didn't get a BrokenPipe error, but can you check on how to reproduce it?
I do this:

>>> cnx = mysql.connector.MySQLConnection(database='test')

Now stop the MySQL server, and do:

>>> cnx.is_connected()

This gives an InterfaceError "Expected OK packet" (which might also not be that good)

Changed in myconnpy:
status: New → Incomplete
Sunfox (sunfox) wrote :

BrokenPipe error occurs if myconnpy is connected to mysql with unix socket:

>>> from mysql.connector import Connect
>>> db = Connect(unix_socket="/var/run/mysqld/mysqld.sock", user="user", password="pwd", database="db")
>>> db.is_connected()
{'insert_id': 0, 'affected_rows': 0, 'field_count': 0, 'warning_count': 0, 'server_status': 0}

now I stop mysqld

>>> db.is_connected()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mysql/connector/connection.py", line 479, in is_connected
    return self.protocol.cmd_ping()
  File "mysql/connector/protocol.py", line 136, in deco
    return func(*args, **kwargs)
  File "mysql/connector/protocol.py", line 614, in cmd_ping
    self.conn.send(pkt,self.next_pktnr)
  File "mysql/connector/connection.py", line 100, in send_plain
    raise errors.OperationalError('%s' % e)
mysql.connector.errors.OperationalError: [Errno 32] Broken pipe

If I use TCP connection instead, returns "Expected OK packet" as You wrote.

IMO is_connected should send command calls in try except and return bool.

Yes, is_connect() will be handling exceptions and only returning a boolean, just like you described. This will be in later releases.
So I guess this bug will be fixed as soon as next release is out (I can't say when), but I think you can easily fix it if you really need is_connected() working the way you want.

Thanks for the bug report!

Changed in myconnpy:
status: Incomplete → In Progress
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers