Skip to content

fix(hedge): assert non-zero rotation period on construction#864

Open
Alpy16 wants to merge 2 commits into
tower-rs:masterfrom
Alpy16:fix-hedge-zero-period
Open

fix(hedge): assert non-zero rotation period on construction#864
Alpy16 wants to merge 2 commits into
tower-rs:masterfrom
Alpy16:fix-hedge-zero-period

Conversation

@Alpy16
Copy link
Copy Markdown

@Alpy16 Alpy16 commented May 21, 2026

Description

This PR addresses an issue where Hedge::new and Hedge::new_with_mock_latencies accept a Duration::ZERO rotation period during configuration. This behavior subsequently causes an unrecoverable integer divide-by-zero panic in RotatingHistogram::maybe_rotate upon the first request invocation.

By validating the period parameter at the API boundary via an explicit assertion, this change ensures that invalid configurations fail-fast during initialization rather than causing runtime instability.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Proposed Changes

  • Added assert!(period > Duration::ZERO, ...) to Hedge::new.
  • Added an identical guard to Hedge::new_with_mock_latencies to protect immediate history pre-population logic.
  • Added synchronous regression tests to the hedge integration test suite covering both constructors.

Verification Run

Executed the module integration tests locally across the workspace using:

cargo test --package tower --all-features

All 7 tests within tests/hedge/main.rs passed successfully alongside the rest of the workspace and doc-test suite.

Closes #862

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.

hedge: zero period is accepted but panics on first call with divide-by-zero

1 participant