Description:
C/Py provides the "close" or "disconnect" functions that gracefully close a connection to a server by sending the QUIT command to the server and then closing the associated socket. This is not useful though when the connection is blocked due to any reason (e.g. network partition).
How to repeat:
Check the code.
Suggested fix:
Implement a shutdown function that does not try to access the server and simply
shuts down the connection to the server.
=== modified file 'python2/mysql/connector/connection.py'
--- python2/mysql/connector/connection.py revid:peeyush.x.gupta@oracle.com-20140514064049-fbztjsjgrk0ln15x
+++ python2/mysql/connector/connection.py 2014-05-19 11:52:34 +0000
@@ -430,6 +430,17 @@
self._open_connection()
self._post_connection()
+ def shutdown(self):
+ """Shut down connection to MySQL Server.
+ """
+ if not self._socket:
+ return
+
+ try:
+ self._socket.shutdown()
+ except (AttributeError, errors.Error):
+ pass # Getting an exception would mean we are disconnected.
+
def disconnect(self):
"""Disconnect from the MySQL server
"""
=== modified file 'python2/mysql/connector/network.py'
--- python2/mysql/connector/network.py revid:peeyush.x.gupta@oracle.com-20140514064049-fbztjsjgrk0ln15x
+++ python2/mysql/connector/network.py 2014-05-19 11:54:52 +0000
@@ -102,6 +102,14 @@
except (socket.error, AttributeError):
pass
+ def shutdown(self):
+ """Shut down the socket."""
+ try:
+ self.sock.shutdown(socket.SHUT_RDWR)
+ del self._packet_queue
+ except (socket.error, AttributeError):
+ pass
+
def send_plain(self, buf, packet_number=None):
"""Send packets to the MySQL server"""
if packet_number is None: