Repository navigation
fix(gossip): swap publisher's sender on subscriber reconnect (#577 H2) - #657
Conversation
Closes the publisher/subscriber desync flagged in #577 H2. Previously `subscriber_task`'s reconnect arm discarded the fresh `GossipSender` from `topic.split()` and `publisher_task` kept broadcasting through the senders captured at spawn. Once the iroh-gossip-side receiver for the original sender was gone, `sender.broadcast(...)` still returned `Ok` (the local `mpsc::Sender` was alive) but no message landed — manual `decdn node announce` and interval-driven publishes silently stopped after any stream reset. Each topic now owns one `Arc<ArcSwap<GossipSender>>` slot shared by the subscriber and the publisher: * The subscriber's reconnect arm stores the fresh sender into its slot before resuming. * The publisher's broadcast loop calls `slot.load_full()` per iteration so the swap is observed without a publisher restart. `GossipSender` is `Clone` (verified in iroh-gossip 0.98 — wraps an `mpsc::Sender<Command>`); `arc-swap` is already a workspace dep, added to `crates/gossip/Cargo.toml`. ArcSwap was chosen over `tokio::sync::watch` (subscriber-task lifetime would poison the publisher's receiver) and `RwLock<HashMap<...>>` (would serialise across topics on every broadcast). A new `publisher_sees_swapped_sender_after_reconnect` test pins the architectural property the fix relies on: the publisher reads through the slot, so a `store` from another task is visible on the next read. The test uses a stand-in `&'static str` value because `GossipSender` can't be easily faked without spinning up a real `iroh_gossip::net::Gossip` instance; a true end-to-end reconnect- publish integration test would warrant its own follow-up PR — the swap mechanism plus the visible single-line `store` call at the reconnect site is the entire fix. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Fixes a gossip publish regression where, after a subscriber reconnect (stream reset + re-subscribe), the publisher could keep broadcasting via a stale GossipSender whose iroh-gossip-side receiver had been dropped—causing manual and periodic announces to stop landing without errors.
Changes:
- Introduces a per-topic shared
Arc<ArcSwap<GossipSender>>sender slot so subscriber reconnects can swap in a fresh sender and the publisher observes it on the next broadcast iteration. - Updates subscriber reconnect logic to
store()the newly-split sender into the shared slot. - Adds a focused unit test to lock in the “publisher reads through slot; subscriber swap is visible next iteration” architectural property.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| crates/gossip/src/service.rs | Shares per-topic sender state via ArcSwap and updates reconnect/publish loops; adds a regression-style unit test for the swap visibility contract. |
| crates/gossip/Cargo.toml | Adds arc-swap as a crate dependency (already present in the workspace). |
| Cargo.lock | Records the arc-swap dependency for decdn-gossip. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request introduces the arc-swap crate to synchronize GossipSender instances between subscriber and publisher tasks. By wrapping the sender in an ArcSwap slot, the publisher can now dynamically load the most recent sender on each iteration, ensuring it does not broadcast through stale senders after a stream reset and reconnection. A new unit test was added to verify this behavior. I have no feedback to provide as there are no review comments.
Coverage reportTotal: 90.04% (was 90.11%, ▼ 0.07%) — 17034/18918 lines
History
|
…est (#577 H2 review) Follow-up on PR #657 review (type-design-analyzer + comment-analyzer + silent-failure-hunter findings): - Introduce private `TopicWiring` struct bundling (name, id, receiver, sender_slot). `subscriber_task` now takes the struct instead of 8 positional args, dropping the `#[allow(clippy::too_many_arguments)]` exemption and making the "subscriber and publisher share one slot per topic" invariant single-site: both vecs derive from the same `Arc::clone(&slot)` at `topic.split()` rather than parallel pushes that must agree by index. - Add `RESUBSCRIBE_FAILED_LABEL = "resubscribe_failed"` and bump it via `metrics.inc_rejected(...)` in the reconnect Err arm alongside the existing `tracing::error!`. Pre-fix this path was log-only — diagnosable but not operationally observable. Operators can now alert on a node stuck in a reconnect loop without scraping logs. Label pinned in the `reject_labels_are_stable` test. - Tighten the `publisher_sees_swapped_sender_after_reconnect` test doc-comment: drop the "diff sites are short and visible by inspection" line (over-promised; future edits push the sites apart) and the trailing "Sanity:" paragraph + `assert_eq!(*first, "initial")` (was testing `arc-swap`'s own contract, not deCDN code). Replace with a sober note that a true end-to-end test requires a live `Gossip` instance and is tracked separately. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…M1) (#659) Closes #577 M3 + M1, the two remaining items from the original review (H2/H3 already shipped in #656/#657). Four commits squashed: - M3: validation.rs trailing-bytes cap (`MAX_TRAILING_BYTES = 4 KiB`, `OversizeTrailingBytes` variant + `oversize_trailing_bytes` label, boundary pair, sig-ordering test) - M1: probe.rs `FrameError::Io → APP_ERR_NO_ERROR` (split out of MALFORMED), named const, truncation integration test - ADR 013: §Application Error Codes table rewritten to match new Io→0x00 mapping (Copilot review) - Forensic `tracing::warn!` at service-layer caller for `OversizeTrailingBytes` only, doc tightenings (5 review-followup items) Detection-only on the M3 side: iroh-gossip 0.98 doesn't expose a per-subscription max-message knob, so the upstream 16 MiB allocation happens before validation. Tracking the deeper fix (per-ALPN frame ceiling) at #660. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
subscriber_task's reconnect arm used to discard the freshGossipSenderfromtopic.split()whilepublisher_taskkept broadcasting through the senders captured at spawn. Once the iroh-gossip-side receiver for the original sender was gone,sender.broadcast(...)still returnedOk(the localmpsc::Senderwas alive) but no message landed — manualdecdn node announceand interval-driven publishes silently stopped after any stream reset.Arc<ArcSwap<GossipSender>>slot shared by the subscriber and the publisher. Subscriber's reconnect stores the fresh sender; publisher reads throughslot.load_full()per iteration so the swap is observed without restarting.GossipSenderisClone(verified in iroh-gossip 0.98 — wraps anmpsc::Sender<Command>);arc-swapwas already a workspace dep (used in the dispatch hot-reload path), added tocrates/gossip/Cargo.toml.Design notes
tokio::sync::watch: watch'sSenderlives in the subscriber task; if that task died the publisher would see a poisoned receiver and have to handle it. ArcSwap stays valid as long as anyArcis alive.RwLock<HashMap<...>>: per-topic slots are lock-free reads; a shared map would serialise publisher iteration across topics and contend with subscribers on every broadcast.Test plan
publisher_sees_swapped_sender_after_reconnect(new) pins the architectural property the fix relies on: the publisher reads through the slot, so astorefrom another task is visible on the next read. Test uses a stand-in&'static strbecauseGossipSendercan't be easily faked without spinning upiroh_gossip::net::Gossip.cargo nextest run -p decdn-gossip— 37/37 pass.cargo nextest run --workspace— 931/931 pass.cargo clippy --workspace --all-targets -- -D warnings— clean.cargo fmt --check— clean.pre-commit run— clean on changed files.A true end-to-end reconnect-publish integration test would spin up two
iroh_gossip::net::Gossipinstances, force a stream reset, and verify the next publish lands. That's out of scope here — no existing harness, and the swap mechanism plus the visible single-linesender_slot.store(...)call at the reconnect site is the entire fix. The reconnect-arm doc comment names the regression test, so a future change that drops the store is immediately visible against the named contract.Still open under #577: M3 trailing-byte padding cap, M1 probe handler I/O classification.
🤖 Generated with Claude Code