@@ -1041,6 +1041,7 @@ def _handle_connection_error(self, error: BaseException, phase: str) -> None:
10411041 # If found, set backoff and add error labels.
10421042 if self .is_sdam or type (error ) not in (AutoReconnect , NetworkTimeout ):
10431043 return
1044+ print ("handling connection error" , id (self ))
10441045 error ._add_error_label ("SystemOverloadedError" )
10451046 error ._add_error_label ("RetryableError" )
10461047 self .backoff ()
@@ -1326,6 +1327,7 @@ async def _get_conn(
13261327 conn = None
13271328 incremented = False
13281329 emitted_event = False
1330+
13291331 try :
13301332 async with self .lock :
13311333 self .active_sockets += 1
@@ -1337,15 +1339,24 @@ async def _get_conn(
13371339 self ._raise_if_not_ready (checkout_started_time , emit_event = False )
13381340 while not (self .conns or self ._pending < self .max_connecting ):
13391341 timeout = deadline - time .monotonic () if deadline else None
1342+ if self ._backoff and (self ._backoff_connection_time > time .monotonic ()):
1343+ timeout = 0.01
13401344 if not await _async_cond_wait (self ._max_connecting_cond , timeout ):
1345+ # Check whether we should continue to wait for the backoff condition.
1346+ if self ._backoff and deadline is None or deadline < time .monotonic ():
1347+ print ("looping?" , id (self ))
1348+ if self ._backoff_connection_time > time .monotonic ():
1349+ print ("continue" , id (self ))
1350+ continue
1351+ print ("break" , id (self ))
1352+ break
13411353 # Timed out, notify the next thread to ensure a
13421354 # timeout doesn't consume the condition.
13431355 if self .conns or self ._pending < self .max_connecting :
13441356 self ._max_connecting_cond .notify ()
13451357 emitted_event = True
13461358 self ._raise_wait_queue_timeout (checkout_started_time )
13471359 self ._raise_if_not_ready (checkout_started_time , emit_event = False )
1348-
13491360 try :
13501361 conn = self .conns .popleft ()
13511362 except IndexError :
@@ -1355,17 +1366,22 @@ async def _get_conn(
13551366 conn = None
13561367 continue
13571368 # See if we need to wait for the backoff period.
1358- elif self ._backoff and (self ._backoff_connection_time < time .monotonic ()):
1369+ elif self ._backoff and (self ._backoff_connection_time > time .monotonic ()):
1370+ print ("wat" , id (self ))
13591371 continue
13601372 else : # We need to create a new connection
1373+ print ("trying a connection" , id (self ))
13611374 try :
13621375 conn = await self .connect (handler = handler )
13631376 finally :
1377+ print ("finished trying a connection" , id (self ))
13641378 async with self ._max_connecting_cond :
13651379 self ._pending -= 1
13661380 self ._max_connecting_cond .notify ()
1381+
13671382 # Catch KeyboardInterrupt, CancelledError, etc. and cleanup.
1368- except BaseException :
1383+ except BaseException as e :
1384+ print ("got an exception" , e , id (self ))
13691385 if conn :
13701386 # We checked out a socket but authentication failed.
13711387 await conn .close_conn (ConnectionClosedReason .ERROR )
@@ -1393,9 +1409,12 @@ async def _get_conn(
13931409 error = ConnectionCheckOutFailedReason .CONN_ERROR ,
13941410 durationMS = duration ,
13951411 )
1412+ print ("raising the exception" , id (self ))
13961413 raise
13971414
13981415 conn .active = True
1416+ if self ._backoff :
1417+ print ("finished get_conn" , id (self ))
13991418 return conn
14001419
14011420 async def checkin (self , conn : AsyncConnection ) -> None :
0 commit comments