Skip to content

Commit 29d01e2

Browse files
committed
factory: raise on closed connections
When connection is closed by the server, but there is no other error, it will be close (is_cloes == True) without setting `last_error`. This is true for all reactors apart from Twisted as far as I can tell. If we try to use such connection, we'll quickly discover that its broken, but we can slightly optimize this process by raising directly from factory().
1 parent 24788e3 commit 29d01e2

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

cassandra/connection.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,8 @@ 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)
989991
else:
990992
return conn
991993

0 commit comments

Comments
 (0)