Skip to content

control-connection fallback: treat pools without live connections as unusable #1014

Description

@dkropachev

Problem

Fallback considers every non-shutdown pool usable:

def _has_usable_node_pool(self):
try:
pools = tuple(self.session._pools.values())
except (AttributeError, TypeError):
return False
return any(pool and not pool.is_shutdown for pool in pools)
def _fallback_to_control_connection(self):
fallback_mode = self.session.cluster.allow_control_connection_query_fallback
if fallback_mode is ControlConnectionQueryFallback.Disabled:
return False
if self._host or self._control_connection_query_attempted:
return False
if fallback_mode is ControlConnectionQueryFallback.SkipPoolCreation:
return True
return not self._has_usable_node_pool()

A pool can remain non-shutdown while having no live connections. Its borrow_connection() then fails, but the pool suppresses control-connection fallback and the request ends with NoHostAvailable.

The current test encodes this behavior:

def test_control_connection_fallback_not_used_when_pool_can_serve(self):
session = self.make_basic_session()
session.cluster.allow_control_connection_query_fallback = ControlConnectionQueryFallback.Fallback
session.cluster._default_load_balancing_policy.make_query_plan.return_value = ['ip1']
pool = Mock(is_shutdown=False)
pool.borrow_connection.side_effect = NoConnectionsAvailable()
session._pools = {'ip1': pool}
connection = self.make_control_connection()
session.cluster.control_connection._connection = connection
rf = self.make_response_future(session)
rf.send_request()
connection.send_msg.assert_not_called()
with pytest.raises(NoHostAvailable):
rf.result()

Expected behavior

Treat pools with no open/live connections as unusable and allow fallback after the query plan is exhausted.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions