Return the connection to the pool, or if it's closed discard it. :param conn: The connection to check into the pool.
(self, conn: Connection)
| 1324 | return conn |
| 1325 | |
| 1326 | def checkin(self, conn: Connection) -> None: |
| 1327 | """Return the connection to the pool, or if it's closed discard it. |
| 1328 | |
| 1329 | :param conn: The connection to check into the pool. |
| 1330 | """ |
| 1331 | txn = conn.pinned_txn |
| 1332 | cursor = conn.pinned_cursor |
| 1333 | conn.active = False |
| 1334 | conn.pinned_txn = False |
| 1335 | conn.pinned_cursor = False |
| 1336 | self.__pinned_sockets.discard(conn) |
| 1337 | listeners = self.opts._event_listeners |
| 1338 | with self.lock: |
| 1339 | self.active_contexts.discard(conn.cancel_context) |
| 1340 | if self.enabled_for_cmap: |
| 1341 | assert listeners is not None |
| 1342 | listeners.publish_connection_checked_in(self.address, conn.id) |
| 1343 | if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG): |
| 1344 | _debug_log( |
| 1345 | _CONNECTION_LOGGER, |
| 1346 | message=_ConnectionStatusMessage.CHECKEDIN, |
| 1347 | clientId=self._client_id, |
| 1348 | serverHost=self.address[0], |
| 1349 | serverPort=self.address[1], |
| 1350 | driverConnectionId=conn.id, |
| 1351 | ) |
| 1352 | if self.pid != os.getpid(): |
| 1353 | self.reset_without_pause() |
| 1354 | else: |
| 1355 | if self.closed: |
| 1356 | conn.close_conn(ConnectionClosedReason.POOL_CLOSED) |
| 1357 | elif conn.closed: |
| 1358 | # CMAP requires the closed event be emitted after the check in. |
| 1359 | if self.enabled_for_cmap: |
| 1360 | assert listeners is not None |
| 1361 | listeners.publish_connection_closed( |
| 1362 | self.address, conn.id, ConnectionClosedReason.ERROR |
| 1363 | ) |
| 1364 | if self.enabled_for_logging and _CONNECTION_LOGGER.isEnabledFor(logging.DEBUG): |
| 1365 | _debug_log( |
| 1366 | _CONNECTION_LOGGER, |
| 1367 | message=_ConnectionStatusMessage.CONN_CLOSED, |
| 1368 | clientId=self._client_id, |
| 1369 | serverHost=self.address[0], |
| 1370 | serverPort=self.address[1], |
| 1371 | driverConnectionId=conn.id, |
| 1372 | reason=_verbose_connection_error_reason(ConnectionClosedReason.ERROR), |
| 1373 | error=ConnectionClosedReason.ERROR, |
| 1374 | ) |
| 1375 | else: |
| 1376 | close_conn = False |
| 1377 | with self.lock: |
| 1378 | # Hold the lock to ensure this section does not race with |
| 1379 | # Pool.reset(). |
| 1380 | if self.stale_generation(conn.generation, conn.service_id): |
| 1381 | close_conn = True |
| 1382 | else: |
| 1383 | conn.update_last_checkin_time() |
no test coverage detected