Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions pymongo/asynchronous/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,7 @@ async def authenticate(self, reauthenticate: bool = False) -> None:
await auth.authenticate(creds, self, reauthenticate=reauthenticate)
self.ready = True
duration = time.monotonic() - self.creation_time
if self.enabled_for_cmap:
assert self.listeners is not None
self.listeners.publish_connection_ready(self.address, self.id, duration)
# Log before publishing event to prevent potential listener preemption in tests
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
Expand All @@ -522,6 +520,9 @@ async def authenticate(self, reauthenticate: bool = False) -> None:
driverConnectionId=self.id,
durationMS=duration,
)
if self.enabled_for_cmap:
assert self.listeners is not None
self.listeners.publish_connection_ready(self.address, self.id, duration)

def validate_session(
self, client: Optional[AsyncMongoClient[Any]], session: Optional[AsyncClientSession]
Expand Down Expand Up @@ -1026,9 +1027,7 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
self.active_contexts.add(tmp_context)

listeners = self.opts._event_listeners
if self.enabled_for_cmap:
assert listeners is not None
listeners.publish_connection_created(self.address, conn_id)
# Log before publishing event to prevent potential listener preemption in tests
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
Expand All @@ -1038,6 +1037,9 @@ async def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> A
serverPort=self.address[1],
driverConnectionId=conn_id,
)
if self.enabled_for_cmap:
assert listeners is not None
listeners.publish_connection_created(self.address, conn_id)

try:
networking_interface = await _configured_protocol_interface(self.address, self.opts)
Expand Down
14 changes: 8 additions & 6 deletions pymongo/synchronous/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,7 @@ def authenticate(self, reauthenticate: bool = False) -> None:
auth.authenticate(creds, self, reauthenticate=reauthenticate)
self.ready = True
duration = time.monotonic() - self.creation_time
if self.enabled_for_cmap:
assert self.listeners is not None
self.listeners.publish_connection_ready(self.address, self.id, duration)
# Log before publishing event to prevent potential listener preemption in tests
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
Expand All @@ -522,6 +520,9 @@ def authenticate(self, reauthenticate: bool = False) -> None:
driverConnectionId=self.id,
durationMS=duration,
)
if self.enabled_for_cmap:
assert self.listeners is not None
self.listeners.publish_connection_ready(self.address, self.id, duration)

def validate_session(
self, client: Optional[MongoClient[Any]], session: Optional[ClientSession]
Expand Down Expand Up @@ -1022,9 +1023,7 @@ def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> Connect
self.active_contexts.add(tmp_context)

listeners = self.opts._event_listeners
if self.enabled_for_cmap:
assert listeners is not None
listeners.publish_connection_created(self.address, conn_id)
# Log before publishing event to prevent potential listener preemption in tests
if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG):
_debug_log(
_CONNECTION_LOGGER,
Expand All @@ -1034,6 +1033,9 @@ def connect(self, handler: Optional[_MongoClientErrorHandler] = None) -> Connect
serverPort=self.address[1],
driverConnectionId=conn_id,
)
if self.enabled_for_cmap:
assert listeners is not None
listeners.publish_connection_created(self.address, conn_id)

try:
networking_interface = _configured_socket_interface(self.address, self.opts)
Expand Down
Loading