Skip to content

pool: fix inverted cooldown check in _get_shard_aware_endpoint#823

Merged
sylwiaszunejko merged 1 commit intoscylladb:masterfrom
nikagra:fix-shard-aware-cooldown-inverted-comparison
Apr 17, 2026
Merged

pool: fix inverted cooldown check in _get_shard_aware_endpoint#823
sylwiaszunejko merged 1 commit intoscylladb:masterfrom
nikagra:fix-shard-aware-cooldown-inverted-comparison

Conversation

@nikagra
Copy link
Copy Markdown

@nikagra nikagra commented Apr 16, 2026

Summary

  • _get_shard_aware_endpoint used block_until < time.time() which is True only after the 10-minute NAT-detection cooldown has expired — the exact opposite of the intended guard.
  • During the cooldown window the shard-aware port was still used; once the window closed, shard-awareness was permanently disabled for the rest of the process.
  • Fix: single-character change <> so the branch suppresses the shard-aware endpoint while the deadline is in the future, and restores it automatically once the deadline passes.
  • Root cause introduced in commit 6eaafc3f (Jul 2020) and undetected because existing tests only covered the happy path.

Test plan

  • python3 -m unittest tests.unit.test_shard_aware passes (3 tests: existing port test + new test_advanced_shard_aware_cooldown covering active-block, expired-block, and hard-disable paths)
  • Verify that the new test fails against the pre-fix code (the two assertions for active block and expired block both invert under the buggy comparison)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes shard-aware endpoint selection in HostConnection._get_shard_aware_endpoint by correcting the cooldown comparison so advanced shard-awareness is suppressed only during the NAT-detection cooldown window and automatically restored after expiry. Adds/extends unit coverage to exercise the cooldown and hard-disable behavior.

Changes:

  • Fix inverted cooldown guard in HostConnection._get_shard_aware_endpoint (<>).
  • Refactor MockSession test helper to module scope for reuse.
  • Add test_advanced_shard_aware_cooldown to cover active cooldown, expired cooldown, and hard-disable paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
cassandra/pool.py Corrects cooldown logic gating shard-aware endpoint selection.
tests/unit/test_shard_aware.py Refactors test scaffolding and adds coverage for cooldown + hard-disable behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/unit/test_shard_aware.py Outdated
Comment thread tests/unit/test_shard_aware.py Outdated
The `block_until < time.time()` condition was true only *after* the
NAT-detection cooldown had already expired, so the shard-aware port
was never suppressed during the 10-minute window and was permanently
disabled once that window closed.  Fix: flip to `>` so the guard
fires while the deadline is in the future.

Add unit test covering the active-block, expired-block, and
hard-disable paths to prevent regression.
@nikagra nikagra force-pushed the fix-shard-aware-cooldown-inverted-comparison branch from 2ae051a to 92a5a3a Compare April 17, 2026 08:21
@nikagra nikagra marked this pull request as ready for review April 17, 2026 08:23
Copy link
Copy Markdown

@Lorak-mmk Lorak-mmk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow

Copy link
Copy Markdown
Collaborator

@sylwiaszunejko sylwiaszunejko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good finding!

@mykaul
Copy link
Copy Markdown

mykaul commented Apr 17, 2026

We should ask AI to look for more areas uncovered by tests...

@sylwiaszunejko sylwiaszunejko merged commit ca5b8c2 into scylladb:master Apr 17, 2026
26 checks passed
@nikagra nikagra deleted the fix-shard-aware-cooldown-inverted-comparison branch April 17, 2026 20:47
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.

5 participants