A single attempt to call hello. Returns a ServerDescription, or raises an exception.
(self)
| 291 | return ServerDescription(address, error=error) |
| 292 | |
| 293 | async def _check_once(self) -> ServerDescription: |
| 294 | """A single attempt to call hello. |
| 295 | |
| 296 | Returns a ServerDescription, or raises an exception. |
| 297 | """ |
| 298 | address = self._server_description.address |
| 299 | sd = self._server_description |
| 300 | |
| 301 | # XXX: "awaited" could be incorrectly set to True in the rare case |
| 302 | # the pool checkout closes and recreates a connection. |
| 303 | awaited = bool( |
| 304 | self._pool.conns and self._stream and sd.is_server_type_known and sd.topology_version |
| 305 | ) |
| 306 | if self._publish: |
| 307 | assert self._listeners is not None |
| 308 | self._listeners.publish_server_heartbeat_started(address, awaited) |
| 309 | |
| 310 | if self._cancel_context and self._cancel_context.cancelled: |
| 311 | await self._reset_connection() |
| 312 | async with self._pool.checkout() as conn: |
| 313 | if _SDAM_LOGGER.isEnabledFor(logging.DEBUG): |
| 314 | _debug_log( |
| 315 | _SDAM_LOGGER, |
| 316 | message=_SDAMStatusMessage.HEARTBEAT_START, |
| 317 | topologyId=self._topology._topology_id, |
| 318 | driverConnectionId=conn.id, |
| 319 | serverConnectionId=conn.server_connection_id, |
| 320 | serverHost=address[0], |
| 321 | serverPort=address[1], |
| 322 | awaited=awaited, |
| 323 | ) |
| 324 | |
| 325 | self._cancel_context = conn.cancel_context |
| 326 | # Record the connection id so we can later attach it to the failed log message. |
| 327 | self._conn_id = conn.id |
| 328 | response, round_trip_time = await self._check_with_socket(conn) |
| 329 | if not response.awaitable: |
| 330 | await self._rtt_monitor.add_sample(round_trip_time) |
| 331 | |
| 332 | avg_rtt, min_rtt = await self._rtt_monitor.get() |
| 333 | sd = ServerDescription(address, response, avg_rtt, min_round_trip_time=min_rtt) |
| 334 | if self._publish: |
| 335 | assert self._listeners is not None |
| 336 | self._listeners.publish_server_heartbeat_succeeded( |
| 337 | address, round_trip_time, response, response.awaitable |
| 338 | ) |
| 339 | if _SDAM_LOGGER.isEnabledFor(logging.DEBUG): |
| 340 | _debug_log( |
| 341 | _SDAM_LOGGER, |
| 342 | message=_SDAMStatusMessage.HEARTBEAT_SUCCESS, |
| 343 | topologyId=self._topology._topology_id, |
| 344 | driverConnectionId=conn.id, |
| 345 | serverConnectionId=conn.server_connection_id, |
| 346 | serverHost=address[0], |
| 347 | serverPort=address[1], |
| 348 | awaited=awaited, |
| 349 | durationMS=round_trip_time * 1000, |
| 350 | reply=response.document, |
no test coverage detected