Skip to content

Commit dc80701

Browse files
committed
connection: tolerate clean startup close
1 parent bcc2d3d commit dc80701

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

cassandra/connection.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -986,8 +986,6 @@ def factory(cls, endpoint, timeout, host_conn = None, *args, **kwargs):
986986
conn.close()
987987
raise OperationTimedOut("Timed out creating connection (%s seconds)" % timeout,
988988
timeout=timeout)
989-
elif conn.is_closed:
990-
raise ConnectionShutdown("Connection to %s was closed by server" % conn.endpoint)
991989
else:
992990
return conn
993991

tests/unit/test_connection.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,30 @@ def test_wait_for_responses_shutdown_includes_last_error(self):
383383
assert "already closed" in error_message
384384
assert "Bad file descriptor" in error_message
385385

386+
def test_factory_returns_cleanly_closed_connection(self):
387+
"""
388+
Clean server closes during startup are left for the owning pool/control
389+
connection to handle so reconnection cadence stays centralized.
390+
"""
391+
392+
class ClosedConnection(Connection):
393+
created = None
394+
395+
def __init__(self, *args, **kwargs):
396+
super(ClosedConnection, self).__init__(*args, **kwargs)
397+
self.is_closed = True
398+
self.connected_event.set()
399+
ClosedConnection.created = self
400+
401+
def close(self):
402+
self.is_closed = True
403+
self.connected_event.set()
404+
405+
conn = ClosedConnection.factory(DefaultEndPoint('1.2.3.4'), timeout=1)
406+
407+
assert conn is ClosedConnection.created
408+
assert conn.is_closed
409+
386410

387411
@patch('cassandra.connection.ConnectionHeartbeat._raise_if_stopped')
388412
class ConnectionHeartbeatTest(unittest.TestCase):

0 commit comments

Comments
 (0)