From c7e6ebbdc7ff0c3c8d24d2a745479da615b0832d Mon Sep 17 00:00:00 2001 From: muzarski Date: Wed, 29 Nov 2023 14:48:57 +0100 Subject: [PATCH] pool: log error when failed to connect to shard The exception from `HostConnection::_open_connection_to_missing_shard` during connection failure is silently dropped by the callers. This function is submitted to the `ThreadPoolExecutor` which assigns the result of this function to the future (either success or exception). The callers throughout the code ignore the future's result and that is why this exception is ignored. In this commit we add an error log when opening a connection to the specific shard fails. --- cassandra/pool.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cassandra/pool.py b/cassandra/pool.py index 315114575c..738fc8e6d6 100644 --- a/cassandra/pool.py +++ b/cassandra/pool.py @@ -719,12 +719,15 @@ def _open_connection_to_missing_shard(self, shard_id): return shard_aware_endpoint = self._get_shard_aware_endpoint() log.debug("shard_aware_endpoint=%r", shard_aware_endpoint) - if shard_aware_endpoint: - conn = self._session.cluster.connection_factory(shard_aware_endpoint, host_conn=self, on_orphaned_stream_released=self.on_orphaned_stream_released, - shard_id=shard_id, - total_shards=self.host.sharding_info.shards_count) - conn.original_endpoint = self.host.endpoint + try: + conn = self._session.cluster.connection_factory(shard_aware_endpoint, host_conn=self, on_orphaned_stream_released=self.on_orphaned_stream_released, + shard_id=shard_id, + total_shards=self.host.sharding_info.shards_count) + conn.original_endpoint = self.host.endpoint + except Exception as exc: + log.error("Failed to open connection to %s, on shard_id=%i: %s", self.host, shard_id, exc) + raise else: conn = self._session.cluster.connection_factory(self.host.endpoint, host_conn=self, on_orphaned_stream_released=self.on_orphaned_stream_released)