@@ -1029,7 +1029,7 @@ async def remove_stale_sockets(self, reference_generation: int) -> None:
10291029 self .requests -= 1
10301030 self .size_cond .notify ()
10311031
1032- def _handle_connection_error (self , error : BaseException , phase : str ) -> None :
1032+ def _handle_connection_error (self , error : BaseException , phase : str , conn_id : int ) -> None :
10331033 # Handle system overload condition for non-sdam pools.
10341034 # Look for an AutoReconnect error raised from a ConnectionResetError with
10351035 # errno == errno.ECONNRESET or raised from an OSError that we've created due to
@@ -1040,7 +1040,18 @@ def _handle_connection_error(self, error: BaseException, phase: str) -> None:
10401040 self ._backoff += 1
10411041 error ._add_error_label ("SystemOverloadedError" )
10421042 error ._add_error_label ("RetryableError" )
1043- print (f"Setting backoff in { phase } :" , self ._backoff ) # noqa: T201
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+ )
10441055
10451056 async def connect (self , handler : Optional [_MongoClientErrorHandler ] = None ) -> AsyncConnection :
10461057 """Connect to Mongo and return a new AsyncConnection.
@@ -1103,7 +1114,7 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
11031114 error = ConnectionClosedReason .ERROR ,
11041115 )
11051116 if context ["has_created_socket" ]:
1106- self ._handle_connection_error (error , "handshake" )
1117+ self ._handle_connection_error (error , "handshake" , conn_id )
11071118 if isinstance (error , (IOError , OSError , * SSLErrors )):
11081119 details = _get_timeout_details (self .opts )
11091120 _raise_connection_failure (self .address , error , timeout_details = details )
@@ -1127,7 +1138,7 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
11271138 except BaseException as e :
11281139 async with self .lock :
11291140 self .active_contexts .discard (conn .cancel_context )
1130- self ._handle_connection_error (e , "hello" )
1141+ self ._handle_connection_error (e , "hello" , conn_id )
11311142 await conn .close_conn (ConnectionClosedReason .ERROR )
11321143 raise
11331144
0 commit comments