Skip to content

Commit 7abc88e

Browse files
loganjLarry
andcommitted
fix(relay): retire the old holder when too many channels are named
The named-channel limit added for `#d` sent a bare CLOSED and returned before the REQ claimed its ID. A same-ID REQ that named more than 2048 channels by group-state `#d` therefore left the previous live subscription or artifact sync registered, with its topics retained, under an ID the client was told is closed. Refuse it through `close::refuse`, like the `#h` limit beside it: the old holder is retired under the lifecycle lock, and the connection is cancelled if CLOSED cannot be queued. Signed-off-by: Logan Johnson <[email protected]> Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
1 parent 9c30155 commit 7abc88e

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎crates/buzz-relay/src/connection.rs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2554,7 +2554,8 @@ pub(crate) mod tests {
25542554
/// An ordinary REQ that `handle_req` itself refuses, before it claims its
25552555
/// ID, still replaces the old holder (NIP-01): a live subscription or an
25562556
/// artifact sync must not keep using an ID the client was told is closed.
2557-
/// Covers the auth, scope, channel-count and database-error refusals.
2557+
/// Covers the auth, scope, channel-count (by `#h` and by group-state `#d`)
2558+
/// and database-error refusals.
25582559
/// Mutation: send any of them as a bare `CLOSED` → RED.
25592560
#[tokio::test]
25602561
async fn in_handler_req_refusal_retires_the_old_holder() {
@@ -2581,6 +2582,11 @@ pub(crate) mod tests {
25812582
serde_json::json!({"kinds": [1], "#h": too_many}),
25822583
"restricted: too many explicit channels",
25832584
),
2585+
(
2586+
authenticated_state(),
2587+
serde_json::json!({"kinds": [39000], "#d": too_many}),
2588+
"restricted: too many explicit channels",
2589+
),
25842590
(
25852591
authenticated_state(),
25862592
serde_json::json!({"search": "x"}),

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,14 @@ pub async fn handle_req(
123123
// confirmed below; bound that set before any membership I/O.
124124
let named_channels = super::system_channels::channels_named_by_filters(&filters);
125125
if named_channels.len() > MAX_EXPLICIT_CHANNEL_VALUES {
126-
conn.send(RelayMessage::closed(
126+
super::close::refuse(
127127
&sub_id,
128128
"restricted: too many explicit channels",
129-
));
129+
&conn,
130+
&state,
131+
)
132+
.await;
133+
access.deny("too_many_channels");
130134
return;
131135
}
132136

0 commit comments

Comments
 (0)