Skip to content

pubsub: follow-ups after subscription-before-stream mcache replay fix (#1398)#1403

Description

@acul71

Follow-up tracking for items called out in PR #1398 (merged) and its review. The merged fix replays mcache from _handle_new_peer when a peer's subscription is processed before the outbound pubsub stream exists.

Disconnect / reconnect hygiene

  • _handle_dead_peer early return (pubsub.py): when peer_id not in self.peers, the handler returns before peer_topics cleanup, so a peer that drops while half-registered can leave stale peer_topics entries.
  • Reconnect replay: _send_recent_messages_to_new_peer has no was_newly_added guard (unlike handle_subscription). After a messy disconnect + reconnect, a peer may receive a full mcache window again even when subscriptions were not newly announced. Mitigation today is mostly receiver seen-cache dedup; sender-side gating may be desirable once disconnect cleanup is fixed.

Deeper fix (separate design)

Maintainability

  • IPubsubRouter: declare optional/async hooks for send_recent_messages and flush_pending_messages instead of additional hasattr(self.router, ...) probes in pubsub.py.

Tests (optional)

  • Tighten test_publish_before_identify_with_subscription_before_stream timing (currently ~7s+) with predicate-based wait_for helpers if available elsewhere in pubsub tests.

Context

  • Original flake: test_publish_before_identify_completes under pytest -n auto (real message-loss race, not a bad test).
  • No separate tracking issue existed before merge; newsfragment 1398.bugfix.rst used PR number per newsfragments/README.md.

/cc @gmelodie

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