From 5a867405e693b559864b0e7a3c5c770cf8e0dbc2 Mon Sep 17 00:00:00 2001 From: Noah Stapp Date: Wed, 14 Feb 2024 16:44:48 -0800 Subject: [PATCH] =?UTF-8?q?Switch=20order=20of=20test=5FConnection=5Fcheck?= =?UTF-8?q?out=5Ffails=5Fdue=5Fto=5Ferror=5Festablish=E2=80=A6=20(#1523)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pymongo/logger.py | 4 +-- pymongo/pool.py | 3 +- .../connection-logging.json | 32 +++++++++---------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/pymongo/logger.py b/pymongo/logger.py index 670c3fe5f..f5a8cf1e4 100644 --- a/pymongo/logger.py +++ b/pymongo/logger.py @@ -75,8 +75,8 @@ _VERBOSE_CONNECTION_ERROR_REASONS = { ConnectionClosedReason.POOL_CLOSED: "Connection pool was closed", ConnectionCheckOutFailedReason.POOL_CLOSED: "Connection pool was closed", ConnectionClosedReason.STALE: "Connection pool was stale", - ConnectionClosedReason.ERROR: "Connection experienced an error", - ConnectionCheckOutFailedReason.CONN_ERROR: "Connection experienced an error", + ConnectionClosedReason.ERROR: "An error occurred while using the connection", + ConnectionCheckOutFailedReason.CONN_ERROR: "An error occurred while trying to establish a new connection", ConnectionClosedReason.IDLE: "Connection was idle too long", ConnectionCheckOutFailedReason.TIMEOUT: "Connection exceeded the specified timeout", } diff --git a/pymongo/pool.py b/pymongo/pool.py index 8844f81b6..0ece6084c 100644 --- a/pymongo/pool.py +++ b/pymongo/pool.py @@ -1132,6 +1132,7 @@ class Connection: serverPort=self.address[1], driverConnectionId=self.id, reason=_verbose_connection_error_reason(reason), + error=reason, ) def _close_conn(self) -> None: @@ -1981,7 +1982,7 @@ class Pool: serverHost=self.address[0], serverPort=self.address[1], driverConnectionId=conn.id, - reason="An error occurred while using the connection", + reason=_verbose_connection_error_reason(ConnectionClosedReason.ERROR), error=ConnectionClosedReason.ERROR, ) else: diff --git a/test/connection_logging/connection-logging.json b/test/connection_logging/connection-logging.json index b3d48f56b..5b3f8c1d4 100644 --- a/test/connection_logging/connection-logging.json +++ b/test/connection_logging/connection-logging.json @@ -425,22 +425,6 @@ } } }, - { - "level": "debug", - "component": "connection", - "data": { - "message": "Connection pool cleared", - "serverHost": { - "$$type": "string" - }, - "serverPort": { - "$$type": [ - "int", - "long" - ] - } - } - }, { "level": "debug", "component": "connection", @@ -486,6 +470,22 @@ "$$exists": true } } + }, + { + "level": "debug", + "component": "connection", + "data": { + "message": "Connection pool cleared", + "serverHost": { + "$$type": "string" + }, + "serverPort": { + "$$type": [ + "int", + "long" + ] + } + } } ] }