@@ -146,7 +146,7 @@ async def acquire(self) -> PoolConnectionProxy:
146146 if self ._setup is not None :
147147 try :
148148 await self ._setup (proxy )
149- except Exception as ex :
149+ except ( Exception , asyncio . CancelledError ) as ex :
150150 # If a user-defined `setup` function fails, we don't
151151 # know if the connection is safe for re-use, hence
152152 # we close it. A new connection will be created
@@ -204,7 +204,7 @@ async def release(self, timeout):
204204 budget -= time .monotonic () - started
205205
206206 await self ._con .reset (timeout = budget )
207- except Exception as ex :
207+ except ( Exception , asyncio . CancelledError ) as ex :
208208 # If the `reset` call failed, terminate the connection.
209209 # A new one will be created when `acquire` is called
210210 # again.
@@ -480,7 +480,7 @@ async def _get_new_connection(self):
480480 if self ._init is not None :
481481 try :
482482 await self ._init (con )
483- except Exception as ex :
483+ except ( Exception , asyncio . CancelledError ) as ex :
484484 # If a user-defined `init` function fails, we don't
485485 # know if the connection is safe for re-use, hence
486486 # we close it. A new connection will be created
@@ -587,7 +587,7 @@ async def _acquire_impl():
587587 ch = await self ._queue .get () # type: PoolConnectionHolder
588588 try :
589589 proxy = await ch .acquire () # type: PoolConnectionProxy
590- except Exception :
590+ except ( Exception , asyncio . CancelledError ) :
591591 self ._queue .put_nowait (ch )
592592 raise
593593 else :
@@ -679,7 +679,7 @@ async def close(self):
679679 ch .close () for ch in self ._holders ]
680680 await asyncio .gather (* close_coros , loop = self ._loop )
681681
682- except Exception :
682+ except ( Exception , asyncio . CancelledError ) :
683683 self .terminate ()
684684 raise
685685
0 commit comments