Skip to content

fix(leader-election): validate lease duration conversions - #193

Merged
GatewayJ merged 1 commit into
rustfs:mainfrom
GatewayJ:fix/issue-1081-lease-duration-validation
Jul 21, 2026
Merged

fix(leader-election): validate lease duration conversions#193
GatewayJ merged 1 commit into
rustfs:mainfrom
GatewayJ:fix/issue-1081-lease-duration-validation

Conversation

@GatewayJ

Copy link
Copy Markdown
Member

Type of Change

  • New Feature
  • Bug Fix
  • Documentation
  • Performance Improvement
  • Test/CI
  • Refactor
  • Other: N/A

Related Issues

Closes rustfs/backlog#1081

Summary of Changes

  • Validate configured lease durations before serializing them into the Kubernetes int32 seconds field.
  • Re-check timing invariants using the persisted whole-second duration.
  • Centralize lease validity evaluation so non-positive durations expire without unchecked casts or panicking date arithmetic.
  • Treat date-range overflow conservatively as still valid to preserve mutual exclusion.
  • Add unit and integration coverage for negative, zero, maximum, serialization, and date-boundary values.

The original issue also proposed clamping large positive durations. This change intentionally preserves every positive int32 duration because Kubernetes and client-go accept and honor those values. A unilateral cap could make a follower acquire before a legitimate holder's declared lease expires, creating two active leaders. Enforcing a smaller maximum would require a separately documented protocol constraint shared by all participants.

Checklist

  • I have read and followed the CONTRIBUTING.md guidelines
  • Passed make pre-commit (fmt-check + clippy + test + console-lint + console-fmt-check)
  • Added/updated necessary tests
  • Documentation updated (if needed)
  • CHANGELOG.md updated under [Unreleased] (N/A: internal reliability fix with no user-facing workflow change)
  • CI/CD passed (pending GitHub Actions)

Impact

  • Breaking change (CRD/API compatibility)
  • Requires doc/config/deployment update
  • Other impact: invalid sub-second or out-of-range leader-election configurations now fail during construction instead of producing invalid Lease records.

Verification

make pre-commit

Additional Notes

Standard Kubernetes API validation rejects non-positive Lease durations, but the leader-election core also supports generic Lock implementations and must remain robust against malformed records. The Kubernetes adapter therefore preserves the wire value, while the core owns validity policy.


Thank you for your contribution! Please ensure your PR follows the community standards (CODE_OF_CONDUCT.md) and sign the CLA if this is your first contribution.

@GatewayJ
GatewayJ marked this pull request as ready for review July 21, 2026 15:55
@GatewayJ
GatewayJ added this pull request to the merge queue Jul 21, 2026
Merged via the queue into rustfs:main with commit cc325e3 Jul 21, 2026
3 checks passed
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.

1 participant