@@ -1083,6 +1083,10 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
10831083 Note that the pool does not keep a reference to the socket -- you
10841084 must call checkin() when you're done with it.
10851085 """
1086+ # Mark whether we were in ready state before starting the process, to
1087+ # handle the case of multiple pending connections.
1088+ was_ready = self .state == PoolState .READY
1089+
10861090 async with self .lock :
10871091 conn_id = self .next_connection_id
10881092 self .next_connection_id += 1
@@ -1131,7 +1135,9 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
11311135 reason = _verbose_connection_error_reason (ConnectionClosedReason .ERROR ),
11321136 error = ConnectionClosedReason .ERROR ,
11331137 )
1134- if context ["has_created_socket" ]:
1138+ if context ["has_created_socket" ] and not (
1139+ was_ready and self .state == PoolState .BACKOFF
1140+ ):
11351141 await self ._handle_connection_error (error , "handshake" )
11361142 if isinstance (error , (IOError , OSError , * SSLErrors )):
11371143 details = _get_timeout_details (self .opts )
@@ -1158,7 +1164,7 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
11581164 except BaseException as e :
11591165 async with self .lock :
11601166 self .active_contexts .discard (conn .cancel_context )
1161- if not has_completed_hello :
1167+ if not has_completed_hello and not ( was_ready and self . state == PoolState . BACKOFF ) :
11621168 await self ._handle_connection_error (e , "hello" )
11631169 await conn .close_conn (ConnectionClosedReason .ERROR )
11641170 raise
0 commit comments