Skip to content

pool: release stopped host reconnection handlers - #1032

Open
dkropachev wants to merge 6 commits into
masterfrom
fix/host-reconnector-releases-slot
Open

dkropachev wants to merge 6 commits into
masterfrom
fix/host-reconnector-releases-slot

Conversation

@dkropachev

Copy link
Copy Markdown

Problem

_HostReconnectionHandler stayed installed in host._reconnection_handler after an authentication failure or after exhausting its retry schedule. Cluster.on_down() then treated that stopped handler as an active reconnection and skipped every later attempt, permanently losing the host for the lifetime of the cluster.

Fix

Release the host reconnection slot whenever its handler will not run again. The update holds the host lock and clears the slot only when it still points to that handler, so a concurrent replacement cannot be removed.

Add unit coverage for authentication failure, schedule exhaustion, continued retries, and the replacement race. Document the fix in the changelog.

No public API, wire protocol, or compatibility behavior changes. The change only corrects internal host-reconnection bookkeeping.

Fixes #1026

Testing

  • TZ=UTC uv run pytest -rf tests/unit — 1061 passed, 40 skipped
  • uvx --from build pyproject-build — sdist and Cython wheel built successfully
  • git diff --check

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce. (Not applicable: no public items added.)
  • I have adjusted the documentation in ./docs/source/. (Not applicable: internal behavior fix; changelog updated.)
  • I added appropriate Fixes: annotations to PR description.

Authentication failures and exhausted retry schedules left their handlers installed on the host. Every later DOWN event then treated the stopped handler as an active reconnection and permanently skipped that host.

Clear the slot under the host lock when the handler will not run again. Only clear it when it still belongs to that handler, so a concurrent replacement remains installed.
@coderabbitai

coderabbitai Bot commented Sep 21, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: QUIET

Plan: Advanced

Run ID: dcfe2fc8-c400-478c-a6fb-b639cc211b53

📥 Commits

Reviewing files that changed from the base of the PR and between 2710b32 and d566921.

📒 Files selected for processing (4)
  • cassandra/cluster.py
  • cassandra/pool.py
  • tests/unit/test_cluster.py
  • tests/unit/test_control_connection.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

_HostReconnectionHandler now releases its host slot when authentication fails, retries are exhausted, or the initial retry schedule is empty. Down-event processing tracks pending work and skips stale or removed hosts. Host removal now supports controlled node refreshes and preserves hosts reindexed under a new host ID. Tests cover these behaviors, and the changelog records the reconnection fix.

Suggested reviewers: mykaul

Priority: ➖ Normal

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to d5669

The change enables fresh reconnection attempts after terminal failures and avoids reconnecting stale or removed hosts. The covered behaviors leave no concrete merge-blocking risk.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR adds unrelated host-removal API and behavior in cassandra/cluster.py: remove_host and on_remove gain refresh_nodes, and remove_host_by_host_id is added. The related tests cover refres… Remove the unrelated host-removal changes and their tests from this PR, or move them to a separate issue and pull request.
Docstring Coverage ⚠️ Warning Docstring coverage is 16.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 50 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: releasing stopped host reconnection handlers.
Description check ✅ Passed The description explains the problem, fix, scope, linked issue, testing, and completed checklist items. It matches the required template.
Linked Issues check ✅ Passed Issue #1026 requires a stopped host reconnector to release its slot after AuthenticationFailed or retry-schedule exhaustion. cassandra/pool.py clears host._reconnection_handler under host.lock
Full details: Out of Scope Changes check

Explanation

The PR adds unrelated host-removal API and behavior in cassandra/cluster.py: remove_host and on_remove gain refresh_nodes, and remove_host_by_host_id is added. The related tests cover refresh suppression and stale host-ID removal. These changes do not implement issue #1026's reconnector-slot release requirement.

  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

After a terminal handler released its slot, ordinary DOWN events still skipped hosts already marked down. Empty retry schedules also stopped before the slot could be released.\n\nRestart reconnection directly for a down host with no active handler, and release a host handler when its schedule is empty before the first attempt.
Repeated DOWN events could start a new reconnector before the original executor task notified policies and removed pools. Removed hosts could take the same path and be reintroduced after a successful attempt.

Track pending DOWN work separately from the reconnector slot, ignore lifecycle work for hosts no longer in metadata, and release pending state when processing or submission ends.
Topology refresh removed missing peers from metadata directly, leaving sessions and load-balancing policies unaware. Route removals through Cluster so DOWN guards cannot strand stale hosts.
A topology refresh already owns a complete peer snapshot, so starting another refresh for each missing host can recurse and race the outer token-map rebuild. Carry refresh suppression through the normal removal lifecycle while preserving reconnects when the active control host is removed.
Topology refresh can temporarily index one Host under both its old and new host IDs. Remove missing entries by snapshot ID and run removal lifecycle only when the Host is no longer tracked, so endpoint replacements remain available.
@dkropachev
dkropachev requested a review from nikagra September 22, 2026 15:04

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Host reconnector that stops for good is never cleared, permanently losing the host

1 participant