Skip to content
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

Old patches: preventing unexpected exceptions and freezes #982

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
12 changes: 7 additions & 5 deletions aiomysql/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,10 +551,7 @@ async def _connect(self):
if self.autocommit_mode is not None:
await self.autocommit(self.autocommit_mode)
except Exception as e:
if self._writer:
self._writer.transport.close()
self._reader = None
self._writer = None
self.close()

# As of 3.11, asyncio.TimeoutError is a deprecated alias of
# OSError. For consistency, we're also considering this an
Expand Down Expand Up @@ -666,7 +663,12 @@ async def _read_bytes(self, num_bytes):
return data

def _write_bytes(self, data):
return self._writer.write(data)
try:
return self._writer.write(data)
except RuntimeError as e:
self.close()
msg = "Lost connection to MySQL server during query ({})".format(e)
raise OperationalError(2013, msg) from e

async def _read_query_result(self, unbuffered=False):
self._result = None
Expand Down
4 changes: 2 additions & 2 deletions aiomysql/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ async def _fill_free_pool(self, override_min):
**self._conn_kwargs)
# raise exception if pool is closing
self._free.append(conn)
self._cond.notify()
finally:
self._acquiring -= 1
self._cond.notify()
if self._free:
return

Expand All @@ -196,9 +196,9 @@ async def _fill_free_pool(self, override_min):
**self._conn_kwargs)
# raise exception if pool is closing
self._free.append(conn)
self._cond.notify()
finally:
self._acquiring -= 1
self._cond.notify()

async def _wakeup(self):
async with self._cond:
Expand Down
Loading