File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -143,7 +143,8 @@ async def connect(self):
143
143
self ._con = con
144
144
145
145
async def acquire (self ) -> PoolConnectionProxy :
146
- if self ._con is None :
146
+ if self ._con is None or self ._con .is_closed ():
147
+ self ._con = None
147
148
await self .connect ()
148
149
149
150
self ._maybe_cancel_inactive_callback ()
Original file line number Diff line number Diff line change @@ -612,6 +612,27 @@ async def worker(pool):
612
612
613
613
self .assertGreaterEqual (N , 50 )
614
614
615
+ async def test_pool_handles_inactive_connection_errors (self ):
616
+ pool = await self .create_pool (database = 'postgres' ,
617
+ min_size = 1 , max_size = 1 )
618
+
619
+ con = await pool .acquire (timeout = POOL_NOMINAL_TIMEOUT )
620
+
621
+ true_con = con ._con
622
+
623
+ await pool .release (con )
624
+
625
+ # we simulate network error by terminating the connection
626
+ true_con .terminate ()
627
+
628
+ # now pool should reopen terminated connection
629
+ con = await pool .acquire (timeout = POOL_NOMINAL_TIMEOUT )
630
+
631
+ self .assertEqual (await con .fetchval ('SELECT 1' ), 1 )
632
+
633
+ await con .close ()
634
+ await pool .close ()
635
+
615
636
616
637
@unittest .skipIf (os .environ .get ('PGHOST' ), 'using remote cluster for testing' )
617
638
class TestHotStandby (tb .ConnectedTestCase ):
You can’t perform that action at this time.
0 commit comments