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

Method _perished

pymongo/synchronous/pool.py:1401–1436  ·  view source on GitHub ↗

Return True and close the connection if it is "perished". This side-effecty function checks if this socket has been idle for for longer than the max idle time, or if the socket has been closed by some external network error, or if the socket's generation is outdated.

(self, conn: Connection)

Source from the content-addressed store, hash-verified

1399 self.size_cond.notify()
1400
1401 def _perished(self, conn: Connection) -> bool:
1402 """Return True and close the connection if it is "perished".
1403
1404 This side-effecty function checks if this socket has been idle for
1405 for longer than the max idle time, or if the socket has been closed by
1406 some external network error, or if the socket's generation is outdated.
1407
1408 Checking sockets lets us avoid seeing *some*
1409 :class:`~pymongo.errors.AutoReconnect` exceptions on server
1410 hiccups, etc. We only check if the socket was closed by an external
1411 error if it has been > 1 second since the socket was checked into the
1412 pool to keep performance reasonable -
1413 we can't avoid AutoReconnects completely anyway.
1414 """
1415 idle_time_seconds = conn.idle_time_seconds()
1416 # If socket is idle, open a new one.
1417 if (
1418 self.opts.max_idle_time_seconds is not None
1419 and idle_time_seconds > self.opts.max_idle_time_seconds
1420 ):
1421 conn.close_conn(ConnectionClosedReason.IDLE)
1422 return True
1423
1424 check_interval_seconds = self._check_interval_seconds
1425 if check_interval_seconds is not None and (
1426 check_interval_seconds == 0 or idle_time_seconds > check_interval_seconds
1427 ):
1428 if conn.conn_closed():
1429 conn.close_conn(ConnectionClosedReason.ERROR)
1430 return True
1431
1432 if self.stale_generation(conn.generation, conn.service_id):
1433 conn.close_conn(ConnectionClosedReason.STALE)
1434 return True
1435
1436 return False
1437
1438 def _raise_wait_queue_timeout(self, checkout_started_time: float) -> NoReturn:
1439 listeners = self.opts._event_listeners

Callers 1

_get_connMethod · 0.95

Calls 4

stale_generationMethod · 0.95
idle_time_secondsMethod · 0.45
close_connMethod · 0.45
conn_closedMethod · 0.45

Tested by

no test coverage detected