Skip to content

Fix for mysql bug 74483/74933 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/mysql/connector/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,12 @@ def recv_plain(self):
"""Receive packets from the MySQL server"""
try:
# Read the header of the MySQL packet, 4 bytes
packet = bytearray(4)
read = self.sock.recv_into(packet, 4)
if read != 4:
raise errors.InterfaceError(errno=2013)
packet = bytearray()
while len(packet) < 4:
chunk = self.sock.recv(1)
if not chunk:
raise errors.InterfaceError(errno=2013)
packet += chunk
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In typically case, sock.recv(4) returns 4 bytes.
Calling socket.recv() 4 times may drop performance significantly.

packet = b''
while len(packet) < 4:
    chunk = self.sock.recv(4-len(packet))
    if not chunk:
        raise errors.InterfaceError(errno=2013)
    packet += chunk

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense ^^

On Fri, Feb 20, 2015, 19:55 INADA Naoki notifications@github.com wrote:

In lib/mysql/connector/network.py
#4 (comment)
:

@@ -220,10 +220,12 @@ def recv_plain(self):
"""Receive packets from the MySQL server"""
try:
# Read the header of the MySQL packet, 4 bytes

  •        packet = bytearray(4)
    
  •        read = self.sock.recv_into(packet, 4)
    
  •        if read != 4:
    
  •            raise errors.InterfaceError(errno=2013)
    
  •        packet = bytearray()
    
  •        while len(packet) < 4:
    
  •            chunk = self.sock.recv(1)
    
  •            if not chunk:
    
  •                raise errors.InterfaceError(errno=2013)
    
  •            packet += chunk
    

In typically case, sock.recv(4) returns 4 bytes.
Calling socket.recv() 4 times may drop performance significantly.

packet = b''while len(packet) < 4:
chunk = self.sock.recv(4-len(packet))
if not chunk:
raise errors.InterfaceError(errno=2013)
packet += chunk


Reply to this email directly or view it on GitHub
https://github.com/mysql/mysql-connector-python/pull/4/files#r25119048.


# Save the packet number and payload length
self._packet_number = packet[3]
Expand Down