Skip to content

fix: Detect clean-session reconnects in Subscription::next_message#81

Merged
KennethKnudsen97 merged 2 commits into
masterfrom
fix/clean-session-subscription-invalidation
May 4, 2026
Merged

fix: Detect clean-session reconnects in Subscription::next_message#81
KennethKnudsen97 merged 2 commits into
masterfrom
fix/clean-session-subscription-invalidation

Conversation

@KennethKnudsen97

Copy link
Copy Markdown
Contributor

Summary

  • New clean_session_count: u8 on Shared, bumped in set_connected only when connected == Some(false).
  • Subscription snapshots the counter at creation; poll_next returns None if the live counter has advanced.
  • Replaces the old clean_session() future, which was structurally unable to observe the transition (see below).

Why the old code didn't work

clean_session() snapshotted prev_state inside a fresh future built on every poll_next. The future acquired the lock after set_connected released it, so prev_state always equalled the post-mutation shared.connected. The pattern (None | Some(true), Some(false)) was never reachable — the "before" half of the comparison was dead-on-arrival.

Test plan

  • Verified on hardware: clean-session reconnect (broker drops session) triggers next_message().await → None, callers resubscribe.
  • Transient disconnects and session-resume reconnects do not invalidate subs (verified via firmware integration test).

Refs FactbirdHQ/rustot#121

Track clean-session reconnects via `clean_session_count: u8` on `Shared`,
bumped in `set_connected` only when `connected == Some(false)`.
`Subscription` snapshots the counter at creation; `poll_next` returns
`None` if the live counter has advanced — i.e. the broker has dropped
our subs since this subscription was created.

Replaces the previous `clean_session()` future. That code snapshotted
`prev_state` inside a future built fresh on every `poll_next` and
acquired the lock *after* `set_connected` released it, so `prev_state`
always equalled the post-mutation `shared.connected`. The pattern
`(None | Some(true), Some(false))` was structurally unreachable.

Transient disconnects and session-resume reconnects do not bump the
counter — broker-side and local subscriber state are intact, so the
subscription stays valid.

Refs FactbirdHQ/rustot#121
@KennethKnudsen97
KennethKnudsen97 merged commit ed97d62 into master May 4, 2026
6 checks passed
@KennethKnudsen97
KennethKnudsen97 deleted the fix/clean-session-subscription-invalidation branch May 4, 2026 10:24
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.

2 participants