Skip to content

Commit c7e6ebb

Browse files
committed
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.
1 parent 8138dca commit c7e6ebb

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

cassandra/pool.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -719,12 +719,15 @@ def _open_connection_to_missing_shard(self, shard_id):
719719
return
720720
shard_aware_endpoint = self._get_shard_aware_endpoint()
721721
log.debug("shard_aware_endpoint=%r", shard_aware_endpoint)
722-
723722
if shard_aware_endpoint:
724-
conn = self._session.cluster.connection_factory(shard_aware_endpoint, host_conn=self, on_orphaned_stream_released=self.on_orphaned_stream_released,
725-
shard_id=shard_id,
726-
total_shards=self.host.sharding_info.shards_count)
727-
conn.original_endpoint = self.host.endpoint
723+
try:
724+
conn = self._session.cluster.connection_factory(shard_aware_endpoint, host_conn=self, on_orphaned_stream_released=self.on_orphaned_stream_released,
725+
shard_id=shard_id,
726+
total_shards=self.host.sharding_info.shards_count)
727+
conn.original_endpoint = self.host.endpoint
728+
except Exception as exc:
729+
log.error("Failed to open connection to %s, on shard_id=%i: %s", self.host, shard_id, exc)
730+
raise
728731
else:
729732
conn = self._session.cluster.connection_factory(self.host.endpoint, host_conn=self, on_orphaned_stream_released=self.on_orphaned_stream_released)
730733

0 commit comments

Comments
 (0)