Checks for and force closes connections that have been alive for too long. It also closes the oldest connections if too many connections are open.
(self, timestamp: datetime.datetime)
| 686 | return True |
| 687 | |
| 688 | def _timeout_connections(self, timestamp: datetime.datetime): |
| 689 | """ |
| 690 | Checks for and force closes connections that have been alive for too long. |
| 691 | It also closes the oldest connections if too many connections are open. |
| 692 | """ |
| 693 | # Force close any connections that have timed out. |
| 694 | # This is based on comparing the time of the current packet, minus |
| 695 | # self.timeout, to each connection's current endtime value. |
| 696 | for conn in list(self._connection_tracker.values()): |
| 697 | if conn.endtime < (timestamp - self.timeout): |
| 698 | self._close_connection(conn) |
| 699 | |
| 700 | # Force close oldest connections if we have too many. |
| 701 | if len(self._connection_tracker) > self.max_open_connections: |
| 702 | connections = sorted(self._connection_tracker.values(), key=lambda conn: conn.endtime, reverse=True) |
| 703 | for conn in connections[self.max_open_connections:]: |
| 704 | self._close_connection(conn) |
| 705 | |
| 706 | # We can produce connections again, now that we have handled lingering old connections. |
| 707 | self._production_ready = True |
| 708 | |
| 709 | def _cleanup_connections(self): |
| 710 | """ |
no test coverage detected