3737from bson import DEFAULT_CODEC_OPTIONS
3838from pymongo import _csot , helpers_shared
3939from pymongo .asynchronous .client_session import _validate_session_write_concern
40- from pymongo .asynchronous .helpers import _backoff , _handle_reauth
40+ from pymongo .asynchronous .helpers import _handle_reauth
4141from pymongo .asynchronous .network import command
4242from pymongo .common import (
4343 MAX_BSON_SIZE ,
@@ -790,7 +790,6 @@ def __init__(
790790 self ._max_connecting_cond = _async_create_condition (self .lock )
791791 self ._pending = 0
792792 self ._client_id = client_id
793- self ._backoff = 0
794793 if self .enabled_for_cmap :
795794 assert self .opts ._event_listeners is not None
796795 self .opts ._event_listeners .publish_pool_created (
@@ -846,8 +845,6 @@ async def _reset(
846845 async with self .size_cond :
847846 if self .closed :
848847 return
849- # Clear the backoff state.
850- self ._backoff = 0
851848 if self .opts .pause_enabled and pause and not self .opts .load_balanced :
852849 old_state , self .state = self .state , PoolState .PAUSED
853850 self .gen .inc (service_id )
@@ -930,11 +927,6 @@ async def _reset(
930927 for conn in sockets :
931928 await conn .close_conn (ConnectionClosedReason .STALE )
932929
933- @property
934- def max_connecting (self ) -> int :
935- """The current max connecting limit for the pool."""
936- return 1 if self ._backoff else self .opts .max_connecting
937-
938930 async def update_is_writable (self , is_writable : Optional [bool ]) -> None :
939931 """Updates the is_writable attribute on all sockets currently in the
940932 Pool.
@@ -1001,7 +993,7 @@ async def remove_stale_sockets(self, reference_generation: int) -> None:
1001993 async with self ._max_connecting_cond :
1002994 # If maxConnecting connections are already being created
1003995 # by this pool then try again later instead of waiting.
1004- if self ._pending >= self .max_connecting :
996+ if self ._pending >= self .opts . max_connecting :
1005997 return
1006998 self ._pending += 1
1007999 incremented = True
@@ -1034,24 +1026,11 @@ def _handle_connection_error(self, error: BaseException, phase: str, conn_id: in
10341026 # Look for an AutoReconnect error raised from a ConnectionResetError with
10351027 # errno == errno.ECONNRESET or raised from an OSError that we've created due to
10361028 # a closed connection.
1037- # If found, set backoff and add error labels.
1029+ # If found, add error labels.
10381030 if self .is_sdam or type (error ) != AutoReconnect :
10391031 return
1040- self ._backoff += 1
10411032 error ._add_error_label ("SystemOverloadedError" )
10421033 error ._add_error_label ("RetryableError" )
1043- # Log the pool backoff message.
1044- if self .enabled_for_logging and _CONNECTION_LOGGER .isEnabledFor (logging .DEBUG ):
1045- _debug_log (
1046- _CONNECTION_LOGGER ,
1047- message = _ConnectionStatusMessage .POOL_BACKOFF ,
1048- clientId = self ._client_id ,
1049- serverHost = self .address [0 ],
1050- serverPort = self .address [1 ],
1051- driverConnectionId = conn_id ,
1052- reason = _verbose_connection_error_reason (ConnectionClosedReason .POOL_BACKOFF ),
1053- error = ConnectionClosedReason .POOL_BACKOFF ,
1054- )
10551034
10561035 async def connect (self , handler : Optional [_MongoClientErrorHandler ] = None ) -> AsyncConnection :
10571036 """Connect to Mongo and return a new AsyncConnection.
@@ -1082,10 +1061,6 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
10821061 driverConnectionId = conn_id ,
10831062 )
10841063
1085- # Apply backoff if applicable.
1086- if self ._backoff :
1087- await asyncio .sleep (_backoff (self ._backoff ))
1088-
10891064 # Pass a context to determine if we successfully create a configured socket.
10901065 context = dict (has_created_socket = False )
10911066
@@ -1126,9 +1101,11 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
11261101 self .active_contexts .discard (tmp_context )
11271102 if tmp_context .cancelled :
11281103 conn .cancel_context .cancel ()
1104+ completed_hello = False
11291105 try :
11301106 if not self .is_sdam :
11311107 await conn .hello ()
1108+ completed_hello = True
11321109 self .is_writable = conn .is_writable
11331110 if handler :
11341111 handler .contribute_socket (conn , completed_handshake = False )
@@ -1138,15 +1115,14 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
11381115 except BaseException as e :
11391116 async with self .lock :
11401117 self .active_contexts .discard (conn .cancel_context )
1141- self ._handle_connection_error (e , "hello" , conn_id )
1118+ if not completed_hello :
1119+ self ._handle_connection_error (e , "hello" , conn_id )
11421120 await conn .close_conn (ConnectionClosedReason .ERROR )
11431121 raise
11441122
11451123 if handler :
11461124 await handler .client ._topology .receive_cluster_time (conn ._cluster_time )
11471125
1148- # Clear the backoff state.
1149- self ._backoff = 0
11501126 return conn
11511127
11521128 @contextlib .asynccontextmanager
@@ -1323,7 +1299,7 @@ async def _get_conn(
13231299 # to be checked back into the pool.
13241300 async with self ._max_connecting_cond :
13251301 self ._raise_if_not_ready (checkout_started_time , emit_event = False )
1326- while not (self .conns or self ._pending < self .max_connecting ):
1302+ while not (self .conns or self ._pending < self .opts . max_connecting ):
13271303 timeout = deadline - time .monotonic () if deadline else None
13281304 if not await _async_cond_wait (self ._max_connecting_cond , timeout ):
13291305 # Timed out, notify the next thread to ensure a
@@ -1469,7 +1445,7 @@ async def _perished(self, conn: AsyncConnection) -> bool:
14691445 :class:`~pymongo.errors.AutoReconnect` exceptions on server
14701446 hiccups, etc. We only check if the socket was closed by an external
14711447 error if it has been > 1 second since the socket was checked into the
1472- pool, or we are in backoff mode, to keep performance reasonable -
1448+ pool to keep performance reasonable -
14731449 we can't avoid AutoReconnects completely anyway.
14741450 """
14751451 idle_time_seconds = conn .idle_time_seconds ()
@@ -1482,8 +1458,6 @@ async def _perished(self, conn: AsyncConnection) -> bool:
14821458 return True
14831459
14841460 check_interval_seconds = self ._check_interval_seconds
1485- if self ._backoff :
1486- check_interval_seconds = 0
14871461 if check_interval_seconds is not None and (
14881462 check_interval_seconds == 0 or idle_time_seconds > check_interval_seconds
14891463 ):
0 commit comments