From 8077388432037f9326f96e17462d4ab7c78f25b4 Mon Sep 17 00:00:00 2001 From: Adam Holmberg Date: Thu, 14 Apr 2016 15:16:22 -0500 Subject: [PATCH] remove connection leak when control conn reconnect during shutdown PYTHON-482 --- cassandra/cluster.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cassandra/cluster.py b/cassandra/cluster.py index a9dacff4..d9817eef 100644 --- a/cassandra/cluster.py +++ b/cassandra/cluster.py @@ -2152,6 +2152,8 @@ class ControlConnection(object): except Exception as exc: errors[host.address] = exc log.warning("[control connection] Error connecting to %s:", host, exc_info=True) + if self._is_shutdown: + raise DriverException("[control connection] Reconnection in progress during shutdown") raise NoHostAvailable("Unable to connect to any servers", errors) @@ -2165,6 +2167,9 @@ class ControlConnection(object): while True: try: connection = self._cluster.connection_factory(host.address, is_control_connection=True) + if self._is_shutdown: + connection.close() + raise DriverException("Reconnecting during shutdown") break except ProtocolVersionUnsupported as e: self._cluster.protocol_downgrade(host.address, e.startup_version) @@ -2266,7 +2271,7 @@ class ControlConnection(object): log.debug("Shutting down control connection") if self._connection: self._connection.close() - del self._connection + self._connection = None def refresh_schema(self, force=False, **kwargs): try: