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