Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(recipe): prevent perpetual re-election if sequence node overflows #731

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

angxiang
Copy link

@angxiang angxiang commented Oct 9, 2023

Once sequence node is incremented beyond 2147483647, the sequence overflows into the negative space. When getting predecessors, cast the node sequence from String to int before comparing.

Closes #730

Why is this needed?

Prevents perpetual re-election if sequence nodes is incremented beyond 2147483647. Previously the sequence node comparison was comparing two Strings, with this change the comparison is done with integers instead. This means that the only re-election due to an integer overflow will happen when incrementing from 2147483647 to -2147483648, but any subsequent increment will not result in a re-election.

Proposed Changes

  • use integer comparison instead of string comparison when comparing sequence nodes

Does this PR introduce any breaking change?

No

pyLock_predecessor = f"{pyLock_prefix}-0000000032"
pyLock = f"{pyLock_prefix}-0000000031"
pyLock_successor = f"{pyLock_prefix}-0000000030"
children = ["hello", pyLock_predecessor, "world", pyLock, pyLock_successor]

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

def test_get_predecessor_with_overflowed_sequence(self):
"""Validate selection of predecessors with negative sequence.

This can occur in case of an integer overflow, if the sequence counter is

Choose a reason for hiding this comment

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

line too long (81 > 79 characters)


def test_get_predecessor_with_overflowed_sequence(self):
"""Validate selection of predecessors with negative sequence.

Choose a reason for hiding this comment

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

blank line contains whitespace

client.get_children.return_value = children
lock = Lock(client, "test")
assert lock._get_predecessor(pyLock) == pyLock_predecessor

Choose a reason for hiding this comment

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

blank line contains whitespace

pyLock_predecessor = f"{pyLock_prefix}0000000030"
pyLock = f"{pyLock_prefix}0000000031"
pyLock_successor = f"{pyLock_prefix}0000000032"
children = ["hello", pyLock_predecessor, "world", pyLock, pyLock_successor]

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

@angxiang angxiang changed the title fix(core): prevent perpetual re-election if sequence node overflows fix(recipe): prevent perpetual re-election if sequence node overflows Oct 9, 2023
Once sequence node is incremented beyond 2147483647, the sequence
overflows into the negative space. When getting predecessors, cast
the node sequence from String to int before comparing.

Closes python-zk#730
@codecov
Copy link

codecov bot commented Oct 9, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (92bd0c2) 96.73% compared to head (87cccbc) 96.65%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #731      +/-   ##
==========================================
- Coverage   96.73%   96.65%   -0.09%     
==========================================
  Files          27       27              
  Lines        3556     3556              
==========================================
- Hits         3440     3437       -3     
- Misses        116      119       +3     
Files Coverage Δ
kazoo/recipe/lock.py 99.28% <100.00%> (-0.36%) ⬇️

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@angxiang angxiang marked this pull request as ready for review October 9, 2023 14:12
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.

Zookeeper sequence node overflow causes perpetual re-election
2 participants