Bug #68005 Python connector regularly and randomly dropping connection with 2013 error
Submitted: 31 Dec 2012 22:13 Modified: 4 Feb 2014 11:24
Reporter: xxxxxxx yyyyyyy Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / Python Severity:S2 (Serious)
Version: OS:MacOS
Assigned to: Geert Vanderkelen CPU Architecture:Any
Tags: 2013

[31 Dec 2012 22:13] xxxxxxx yyyyyyy
Description:
Almost every query was failing with this error code. I looked at the source code and found that it is calling socket.recv(n) and always just expecting that n bytes will be returned. This is NOT the case. UP TO n bytes will be returned.

This may work on other platforms but it is not reliable at all.

I looked a lot of discussions of the error and they mentioned server side configuration, query size, etc. None of these answers are correct. See my suggested fix below.

How to repeat:
Use the connector to do a series of queries. A bunch will likely fail with the error code 2013.

Suggested fix:
I don't know how portable this is (it should actually be very portable), but I changed the recv calls in network.py to:

self.sock.recv(n, socket.MSG_WAITALL)

...and magically, I got 0 failures where I was constantly getting failures before.

Amazing!
[3 Jan 2013 12:54] Geert Vanderkelen
Which version of Connector/Python was used? If not v1.0.8, can you use that one?