python-zk / kazoo

Kazoo is a high-level Python library that makes it easier to use Apache Zookeeper.
https://kazoo.readthedocs.io
Apache License 2.0
1.3k stars 386 forks source link

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

Open angxiang opened 11 months ago

angxiang commented 11 months ago

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

Does this PR introduce any breaking change?

No

codecov[bot] commented 11 months ago

Codecov Report

All modified lines are covered by tests :white_check_mark:

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

Additional details and impacted files ```diff @@ 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](https://app.codecov.io/gh/python-zk/kazoo/pull/731?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-zk) | Coverage Δ | | |---|---|---| | [kazoo/recipe/lock.py](https://app.codecov.io/gh/python-zk/kazoo/pull/731?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-zk#diff-a2F6b28vcmVjaXBlL2xvY2sucHk=) | `99.28% <100.00%> (-0.36%)` | :arrow_down: | ... and [4 files with indirect coverage changes](https://app.codecov.io/gh/python-zk/kazoo/pull/731/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=python-zk)

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.