Skip to content

Commit 3d067a8

Browse files
TheSentinel454Elrondclaude
committed
fix(relay): deny fan-out for a missing channel instead of retrying it
The access gate counted ChannelNotFound as a failed check, so the new re-check held an event for a deleted channel (such as the deletion event itself) on its worker for 30 s and then closed its recipients. A missing channel grants no one access; the gate now says so, as main did before the unverified path existed. Co-authored-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz> Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Luke Tornquist <[email protected]>
1 parent ed64e49 commit 3d067a8

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎crates/buzz-relay/src/handlers/event.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,9 @@ async fn check_fanout_access(
254254
match visibility {
255255
Ok(v) if v != "private" => return verified(matches),
256256
Ok(_) => {}
257+
// A deleted channel grants no one access. That is an answer, not a
258+
// failed check, so its recipients are not unverified.
259+
Err(buzz_db::DbError::ChannelNotFound(_)) => return verified(Vec::new()),
257260
Err(e) => {
258261
// Fail closed: if we cannot determine visibility, do not leak a
259262
// possibly-private channel's events.

‎crates/buzz-relay/src/handlers/multinode_fanout.rs‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,50 @@ mod tests {
731731
assert!(!cancel.is_cancelled());
732732
}
733733

734+
mod postgres_tests {
735+
use super::*;
736+
737+
/// An event for a channel the database does not have (deleted, or
738+
/// never created here) reaches no one, and is not retried: a missing
739+
/// channel is an answer, not a failed check. Retrying it would hold
740+
/// its worker until the deadline and then close its recipients.
741+
/// Mutation: drop the `ChannelNotFound` arm in `check_fanout_access`
742+
/// -> retried for 30 s and queued to close -> RED.
743+
#[tokio::test]
744+
#[ignore = "requires Postgres — runs in postgres-ci nextest lane"]
745+
async fn event_for_a_missing_channel_is_denied_not_retried() {
746+
let state = crate::state::tests::test_state().await;
747+
let channel_id = Uuid::new_v4();
748+
let (conn, mut frames, cancel) = subscriber(&state, STORED);
749+
state.sub_registry.register(
750+
conn,
751+
"channel".to_string(),
752+
vec![Filter::new().kind(Kind::Custom(STORED))],
753+
Some(channel_id),
754+
);
755+
let closer = LagCloser::default();
756+
757+
let started = std::time::Instant::now();
758+
deliver_or_lose(
759+
&state,
760+
&closer,
761+
Queued::new(ChannelEvent {
762+
topic: EventTopic::Channel(channel_id),
763+
..event(STORED, 0)
764+
}),
765+
)
766+
.await;
767+
assert!(
768+
started.elapsed() < Duration::from_secs(5),
769+
"not retried: {:?}",
770+
started.elapsed()
771+
);
772+
assert!(frames.try_recv().is_err(), "no one has access");
773+
assert!(closer.pending.lock().expect("pending").is_empty());
774+
assert!(!cancel.is_cancelled());
775+
}
776+
}
777+
734778
/// The deadline runs from Redis receipt: an event that already waited out
735779
/// its deadline in the broadcast before dispatch is lost, not delivered.
736780
#[tokio::test(start_paused = true)]

0 commit comments

Comments
 (0)