Skip to content

fix(sse): saturate exponential reconnect backoff #1198

Description

@jstar0

Problem

ExponentialBackoff::retry computes the reconnect multiplier as 2^current_times using u32::pow. With max_times unset, current_times can reach 32; in debug builds this overflows and panics, while release arithmetic can wrap and produce an incorrect delay. The resulting behavior makes a long-lived SSE client vulnerable to a retry-loop panic or unexpectedly short backoff.

Proposed direction

Saturate the multiplier at u32::MAX once current_times reaches the bit width, then use saturating multiplication for the base duration. This keeps the existing unbounded policy while making the delay monotonic and panic-free.

Verification

A focused regression at current_times = 32 reproduces the overflow on the pre-fix implementation and passes with the saturating calculation. The rmcp test suite and clippy checks pass on the proposed patch.

Would maintainers like this fix submitted as a PR?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions