diff --git a/aiomysql/connection.py b/aiomysql/connection.py index 3520dfcc..0b84fe46 100644 --- a/aiomysql/connection.py +++ b/aiomysql/connection.py @@ -666,7 +666,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 diff --git a/aiomysql/pool.py b/aiomysql/pool.py index eaaddbe0..d0bfa82d 100644 --- a/aiomysql/pool.py +++ b/aiomysql/pool.py @@ -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 @@ -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: