@@ -250,6 +250,7 @@ async def _configured_protocol_interface(
250250 address : _Address ,
251251 options : PoolOptions ,
252252 protocol_kls : type [PyMongoBaseProtocol ] = PyMongoProtocol ,
253+ context : dict [str , bool ] | None = None ,
253254) -> AsyncNetworkingInterface :
254255 """Given (host, port) and PoolOptions, return a configured AsyncNetworkingInterface.
255256
@@ -261,6 +262,10 @@ async def _configured_protocol_interface(
261262 ssl_context = options ._ssl_context
262263 timeout = options .socket_timeout
263264
265+ # Signal that we have created the socket successfully.
266+ if context :
267+ context ["has_created_socket" ] = True
268+
264269 if ssl_context is None :
265270 return AsyncNetworkingInterface (
266271 await asyncio .get_running_loop ().create_connection (
@@ -374,7 +379,7 @@ def _create_connection(address: _Address, options: PoolOptions) -> socket.socket
374379
375380
376381def _configured_socket_interface (
377- address : _Address , options : PoolOptions , * args : Any
382+ address : _Address , options : PoolOptions , * args : Any , context : dict [ str , bool ] | None = None
378383) -> NetworkingInterface :
379384 """Given (host, port) and PoolOptions, return a NetworkingInterface wrapping a configured socket.
380385
@@ -385,6 +390,10 @@ def _configured_socket_interface(
385390 sock = _create_connection (address , options )
386391 ssl_context = options ._ssl_context
387392
393+ # Signal that we have created the socket successfully.
394+ if context :
395+ context ["has_created_socket" ] = True
396+
388397 if ssl_context is None :
389398 sock .settimeout (options .socket_timeout )
390399 return NetworkingInterface (sock )
0 commit comments