MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / _check_server

Method _check_server

pymongo/synchronous/monitor.py:252–289  ·  view source on GitHub ↗

Call hello or read the next streaming response. Returns a ServerDescription.

(self)

Source from the content-addressed store, hash-verified

250 self._rtt_monitor.close()
251
252 def _check_server(self) -> ServerDescription:
253 """Call hello or read the next streaming response.
254
255 Returns a ServerDescription.
256 """
257 self._conn_id = None
258 start = time.monotonic()
259 try:
260 return self._check_once()
261 except ReferenceError:
262 raise
263 except Exception as error:
264 _sanitize(error)
265 sd = self._server_description
266 address = sd.address
267 duration = _monotonic_duration(start)
268 awaited = bool(self._stream and sd.is_server_type_known and sd.topology_version)
269 if self._publish:
270 assert self._listeners is not None
271 self._listeners.publish_server_heartbeat_failed(address, duration, error, awaited)
272 if _SDAM_LOGGER.isEnabledFor(logging.DEBUG):
273 _debug_log(
274 _SDAM_LOGGER,
275 message=_SDAMStatusMessage.HEARTBEAT_FAIL,
276 topologyId=self._topology._topology_id,
277 serverHost=address[0],
278 serverPort=address[1],
279 awaited=awaited,
280 durationMS=duration * 1000,
281 failure=error,
282 driverConnectionId=self._conn_id,
283 )
284 self._reset_connection()
285 if isinstance(error, _OperationCancelled):
286 raise
287 self._rtt_monitor.reset()
288 # Server type defaults to Unknown.
289 return ServerDescription(address, error=error)
290
291 def _check_once(self) -> ServerDescription:
292 """A single attempt to call hello.

Callers 1

_runMethod · 0.95

Calls 8

_check_onceMethod · 0.95
_reset_connectionMethod · 0.95
_debug_logFunction · 0.90
ServerDescriptionClass · 0.90
_sanitizeFunction · 0.70
_monotonic_durationFunction · 0.70
resetMethod · 0.45

Tested by

no test coverage detected