Skip to content

Commit

Permalink
Fix wait_for_schema_agreement deadlock
Browse files Browse the repository at this point in the history
Fixes #168

Fix works by extracting part of on_down that marks host as down
out of the executor - so it does not need to wait for free thread.
When host is marked as down, wait_for_schema_agreement can finish,
which in turn enables rest of on_down (the part that still runs on
executor) to be executed.
  • Loading branch information
Lorak-mmk committed Sep 26, 2023
1 parent 7c9df85 commit 7b287a8
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions cassandra/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -2003,6 +2003,17 @@ def _start_reconnector(self, host, is_host_addition):
reconnector.start()

@run_in_executor
def on_down_potentially_blocking(self, host, is_host_addition):
self.profile_manager.on_down(host)
self.control_connection.on_down(host)
for session in tuple(self.sessions):
session.on_down(host)

for listener in self.listeners:
listener.on_down(host)

self._start_reconnector(host, is_host_addition)

def on_down(self, host, is_host_addition, expect_host_to_be_down=False):
"""
Intended for internal use only.
Expand All @@ -2028,18 +2039,9 @@ def on_down(self, host, is_host_addition, expect_host_to_be_down=False):
host.set_down()
if (not was_up and not expect_host_to_be_down) or host.is_currently_reconnecting():
return

log.warning("Host %s has been marked down", host)

self.profile_manager.on_down(host)
self.control_connection.on_down(host)
for session in tuple(self.sessions):
session.on_down(host)

for listener in self.listeners:
listener.on_down(host)

self._start_reconnector(host, is_host_addition)
self.on_down_potentially_blocking(host, is_host_addition)

def on_add(self, host, refresh_nodes=True):
if self.is_shutdown:
Expand Down

0 comments on commit 7b287a8

Please sign in to comment.