Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Nothing4You committed Jan 12, 2022
1 parent 4274fbc commit 381f006
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions aiomysql/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pymysql.constants import SERVER_STATUS
from pymysql.constants import CLIENT
from pymysql.constants import COMMAND
from pymysql.constants import CR
from pymysql.constants import FIELD_TYPE
from pymysql.util import byte2int, int2byte
from pymysql.converters import (escape_item, encoders, decoders,
Expand Down Expand Up @@ -470,7 +471,7 @@ async def set_charset(self, charset):

async def _connect(self):
# TODO: Set close callback
# raise OperationalError(2006,
# raise OperationalError(CR.CR_SERVER_GONE_ERROR,
# "MySQL server has gone away (%r)" % (e,))
try:
if self._unix_socket and self._host in ('localhost', '127.0.0.1'):
Expand Down Expand Up @@ -569,6 +570,13 @@ async def _read_packet(self, packet_type=MysqlPacket):
# we increment in both write_packet and read_packet. The count
# is reset at new COMMAND PHASE.
if packet_number != self._next_seq_id:
if packet_number == 0:
# MySQL 8.0 sends error packet with seqno==0 when shutdown
self.close()
raise OperationalError(
CR.CR_SERVER_LOST,
"Lost connection to MySQL server during query")

raise InternalError(
"Packet sequence number wrong - got %d expected %d" %
(packet_number, self._next_seq_id))
Expand Down Expand Up @@ -596,10 +604,12 @@ async def _read_bytes(self, num_bytes):
data = await self._reader.readexactly(num_bytes)
except asyncio.IncompleteReadError as e:
msg = "Lost connection to MySQL server during query"
raise OperationalError(2013, msg) from e
self.close()
raise OperationalError(CR.CR_SERVER_LOST, msg) from e
except (IOError, OSError) as e:
msg = "Lost connection to MySQL server during query (%s)" % (e,)
raise OperationalError(2013, msg) from e
self.close()
raise OperationalError(CR.CR_SERVER_LOST, msg) from e
return data

def _write_bytes(self, data):
Expand Down
2 changes: 1 addition & 1 deletion aiomysql/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def _acquire(self):
await self._cond.wait()

async def _fill_free_pool(self, override_min):
# iterate over free connections and remove timeouted ones
# iterate over free connections and remove timed out ones
free_size = len(self._free)
n = 0
while n < free_size:
Expand Down

0 comments on commit 381f006

Please sign in to comment.