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 ,
@@ -788,9 +788,9 @@ def __init__(
788788 # Enforces: maxConnecting
789789 # Also used for: clearing the wait queue
790790 self ._max_connecting_cond = _async_create_condition (self .lock )
791+ self ._max_connecting = self .opts .max_connecting
791792 self ._pending = 0
792793 self ._client_id = client_id
793- self ._backoff = 0
794794 if self .enabled_for_cmap :
795795 assert self .opts ._event_listeners is not None
796796 self .opts ._event_listeners .publish_pool_created (
@@ -846,8 +846,6 @@ async def _reset(
846846 async with self .size_cond :
847847 if self .closed :
848848 return
849- # Clear the backoff state.
850- self ._backoff = 0
851849 if self .opts .pause_enabled and pause and not self .opts .load_balanced :
852850 old_state , self .state = self .state , PoolState .PAUSED
853851 self .gen .inc (service_id )
@@ -930,11 +928,6 @@ async def _reset(
930928 for conn in sockets :
931929 await conn .close_conn (ConnectionClosedReason .STALE )
932930
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-
938931 async def update_is_writable (self , is_writable : Optional [bool ]) -> None :
939932 """Updates the is_writable attribute on all sockets currently in the
940933 Pool.
@@ -1001,7 +994,7 @@ async def remove_stale_sockets(self, reference_generation: int) -> None:
1001994 async with self ._max_connecting_cond :
1002995 # If maxConnecting connections are already being created
1003996 # by this pool then try again later instead of waiting.
1004- if self ._pending >= self .max_connecting :
997+ if self ._pending >= self ._max_connecting :
1005998 return
1006999 self ._pending += 1
10071000 incremented = True
@@ -1029,30 +1022,6 @@ async def remove_stale_sockets(self, reference_generation: int) -> None:
10291022 self .requests -= 1
10301023 self .size_cond .notify ()
10311024
1032- def _handle_connection_error (self , error : BaseException , phase : str , conn_id : int ) -> None :
1033- # Handle system overload condition for non-sdam pools.
1034- # Look for an AutoReconnect error raised from a ConnectionResetError with
1035- # errno == errno.ECONNRESET or raised from an OSError that we've created due to
1036- # a closed connection.
1037- # If found, set backoff and add error labels.
1038- if self .is_sdam or type (error ) != AutoReconnect :
1039- return
1040- self ._backoff += 1
1041- error ._add_error_label ("SystemOverloadedError" )
1042- 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- )
1055-
10561025 async def connect (self , handler : Optional [_MongoClientErrorHandler ] = None ) -> AsyncConnection :
10571026 """Connect to Mongo and return a new AsyncConnection.
10581027
@@ -1082,17 +1051,8 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
10821051 driverConnectionId = conn_id ,
10831052 )
10841053
1085- # Apply backoff if applicable.
1086- if self ._backoff :
1087- await asyncio .sleep (_backoff (self ._backoff ))
1088-
1089- # Pass a context to determine if we successfully create a configured socket.
1090- context = dict (has_created_socket = False )
1091-
10921054 try :
1093- networking_interface = await _configured_protocol_interface (
1094- self .address , self .opts , context = context
1095- )
1055+ networking_interface = await _configured_protocol_interface (self .address , self .opts )
10961056 # Catch KeyboardInterrupt, CancelledError, etc. and cleanup.
10971057 except BaseException as error :
10981058 async with self .lock :
@@ -1113,11 +1073,10 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
11131073 reason = _verbose_connection_error_reason (ConnectionClosedReason .ERROR ),
11141074 error = ConnectionClosedReason .ERROR ,
11151075 )
1116- if context ["has_created_socket" ]:
1117- self ._handle_connection_error (error , "handshake" , conn_id )
11181076 if isinstance (error , (IOError , OSError , * SSLErrors )):
11191077 details = _get_timeout_details (self .opts )
11201078 _raise_connection_failure (self .address , error , timeout_details = details )
1079+
11211080 raise
11221081
11231082 conn = AsyncConnection (networking_interface , self , self .address , conn_id , self .is_sdam ) # type: ignore[arg-type]
@@ -1135,18 +1094,15 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
11351094
11361095 await conn .authenticate ()
11371096 # Catch KeyboardInterrupt, CancelledError, etc. and cleanup.
1138- except BaseException as e :
1097+ except BaseException :
11391098 async with self .lock :
11401099 self .active_contexts .discard (conn .cancel_context )
1141- self ._handle_connection_error (e , "hello" , conn_id )
11421100 await conn .close_conn (ConnectionClosedReason .ERROR )
11431101 raise
11441102
11451103 if handler :
11461104 await handler .client ._topology .receive_cluster_time (conn ._cluster_time )
11471105
1148- # Clear the backoff state.
1149- self ._backoff = 0
11501106 return conn
11511107
11521108 @contextlib .asynccontextmanager
@@ -1323,12 +1279,12 @@ async def _get_conn(
13231279 # to be checked back into the pool.
13241280 async with self ._max_connecting_cond :
13251281 self ._raise_if_not_ready (checkout_started_time , emit_event = False )
1326- while not (self .conns or self ._pending < self .max_connecting ):
1282+ while not (self .conns or self ._pending < self ._max_connecting ):
13271283 timeout = deadline - time .monotonic () if deadline else None
13281284 if not await _async_cond_wait (self ._max_connecting_cond , timeout ):
13291285 # Timed out, notify the next thread to ensure a
13301286 # timeout doesn't consume the condition.
1331- if self .conns or self ._pending < self .max_connecting :
1287+ if self .conns or self ._pending < self ._max_connecting :
13321288 self ._max_connecting_cond .notify ()
13331289 emitted_event = True
13341290 self ._raise_wait_queue_timeout (checkout_started_time )
@@ -1469,8 +1425,8 @@ async def _perished(self, conn: AsyncConnection) -> bool:
14691425 :class:`~pymongo.errors.AutoReconnect` exceptions on server
14701426 hiccups, etc. We only check if the socket was closed by an external
14711427 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 -
1473- we can't avoid AutoReconnects completely anyway.
1428+ pool, to keep performance reasonable - we can't avoid AutoReconnects
1429+ completely anyway.
14741430 """
14751431 idle_time_seconds = conn .idle_time_seconds ()
14761432 # If socket is idle, open a new one.
@@ -1481,11 +1437,8 @@ async def _perished(self, conn: AsyncConnection) -> bool:
14811437 await conn .close_conn (ConnectionClosedReason .IDLE )
14821438 return True
14831439
1484- check_interval_seconds = self ._check_interval_seconds
1485- if self ._backoff :
1486- check_interval_seconds = 0
1487- if check_interval_seconds is not None and (
1488- check_interval_seconds == 0 or idle_time_seconds > check_interval_seconds
1440+ if self ._check_interval_seconds is not None and (
1441+ self ._check_interval_seconds == 0 or idle_time_seconds > self ._check_interval_seconds
14891442 ):
14901443 if conn .conn_closed ():
14911444 await conn .close_conn (ConnectionClosedReason .ERROR )
0 commit comments