Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

divideDave avatar image
divideDave asked steve.lacerda answered

Python driver does not honor timeouts set outside the Cluster() constructor

Is this the proper form to report Python driver bugs? I have one oddball server where connections to the Cassandra database frequently timeout without specifying a connection-timeout.

While trying to connect to the Cassandra database (version 3.11.10) using the python 3.25.0 driver I encountered the following issue:

I can connect to the DB using the following code snippet:

self.cluster = Cluster(execution_profiles={EXEC_PROFILE_DEFAULT: self.profile},
control_connection_timeout=180, connect_timeout=180)
self.session = self.cluster.connect('foo')

I cannot connect to the DB using the following code snippet:

self.cluster = Cluster(execution_profiles={EXEC_PROFILE_DEFAULT: self.profile})
self.cluster.connect_timeout = 180
self.cluster.control_connection_timeout = 180
self.session = self.cluster.connect('foo')

When using the defective code above the following exception is returned within 5 seconds, the driver is not honoring the cluster.connect_timeout and/or the control_connection_timeout settings when they are made outside of the Custer()'s constructor.

Traceback (most recent call last):
File "/opt/ngp/idservice-data-cleanup/python/idservice_cleanup.py", line 438, in <module>
if __name__ == "__main__": main()
File "/opt/ngp/idservice-data-cleanup/python/idservice_cleanup.py", line 435, in main
cleaner = CassandraCleaner()
File "/opt/ngp/idservice-data-cleanup/python/idservice_cleanup.py", line 43, in __init__
self.session = self.cluster.connect('foo')
File "/opt/ngp/idservice-data-cleanup/lib64/python2.7/site-packages/cassandra/cluster.py", line 1690, in connect
self.control_connection.connect()
File "/opt/ngp/idservice-data-cleanup/lib64/python2.7/site-packages/cassandra/cluster.py", line 3488, in connect
self._set_new_connection(self._reconnect_internal())
File "/opt/ngp/idservice-data-cleanup/lib64/python2.7/site-packages/cassandra/cluster.py", line 3533, in _reconnect_internal
raise NoHostAvailable("Unable to connect to any servers", errors)
cassandra.cluster.NoHostAvailable: ('Unable to connect to any servers', {'127.0.0.1:9042': OperationTimedOut('errors=None, last_host=None',)})
python driver
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

steve.lacerda avatar image
steve.lacerda answered

The two code snippets are not the same. In the first you are instantiating the Cluster object with certain properties, in the second you are adding properties to the cluster object which never get instantiated. They are not synonymous examples.

Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.