Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix message storm when using multiple peers with multicast #1615

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 1 addition & 29 deletions zenoh/src/net/routing/dispatcher/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ pub fn route_data(
reliability,
)
}
} else if tables.whatami == WhatAmI::Router {
} else {
let route = route
.values()
.filter(|(outface, _key_expr, _context)| {
Expand Down Expand Up @@ -481,34 +481,6 @@ pub fn route_data(
reliability,
)
}
} else {
drop(tables);
for (outface, key_expr, context) in route.values() {
if face.id != outface.id
&& match (face.mcast_group.as_ref(), outface.mcast_group.as_ref()) {
(Some(l), Some(r)) => l != r,
_ => true,
}
{
#[cfg(feature = "stats")]
if !admin {
inc_stats!(face, tx, user, msg.payload)
} else {
inc_stats!(face, tx, admin, msg.payload)
}

outface.primitives.send_push(
Push {
wire_expr: key_expr.into(),
ext_qos: msg.ext_qos,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType { node_id: *context },
payload: msg.payload.clone(),
},
reliability,
)
}
}
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions zenoh/src/net/routing/hat/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,8 @@ impl HatBaseTrait for HatCode {
_expr: &mut RoutingExpr,
) -> bool {
src_face.id != out_face.id
&& match (src_face.mcast_group.as_ref(), out_face.mcast_group.as_ref()) {
(Some(l), Some(r)) => l != r,
_ => true,
}
&& out_face.mcast_group.is_none()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to avoid sending data to a multicast group when in client mode.
This is also to align with zenoh-pico where joining a multicast group can only be done when in peer mode.

&& src_face.mcast_group.is_none()
}

fn info(&self, _tables: &Tables, _kind: WhatAmI) -> String {
Expand Down
5 changes: 1 addition & 4 deletions zenoh/src/net/routing/hat/linkstate_peer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,10 +452,7 @@ impl HatBaseTrait for HatCode {
_expr: &mut RoutingExpr,
) -> bool {
src_face.id != out_face.id
&& match (src_face.mcast_group.as_ref(), out_face.mcast_group.as_ref()) {
(Some(l), Some(r)) => l != r,
_ => true,
}
&& (out_face.mcast_group.is_none() || src_face.mcast_group.is_none())
}

fn info(&self, tables: &Tables, kind: WhatAmI) -> String {
Expand Down
6 changes: 2 additions & 4 deletions zenoh/src/net/routing/hat/p2p_peer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,8 @@ impl HatBaseTrait for HatCode {
_expr: &mut RoutingExpr,
) -> bool {
src_face.id != out_face.id
&& match (src_face.mcast_group.as_ref(), out_face.mcast_group.as_ref()) {
(Some(l), Some(r)) => l != r,
_ => true,
}
&& (out_face.mcast_group.is_none()
|| (src_face.whatami == WhatAmI::Client && src_face.mcast_group.is_none()))
}

fn info(&self, _tables: &Tables, _kind: WhatAmI) -> String {
Expand Down
36 changes: 20 additions & 16 deletions zenoh/src/net/routing/hat/p2p_peer/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,22 +193,26 @@ fn declare_simple_subscription(
// This introduced a buffer overflow on windows
// TODO: Let's deactivate this on windows until Fixed
#[cfg(not(windows))]
for mcast_group in &tables.mcast_groups {
mcast_group
.primitives
.send_declare(RoutingContext::with_expr(
Declare {
interest_id: None,
ext_qos: ext::QoSType::DECLARE,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::DEFAULT,
body: DeclareBody::DeclareSubscriber(DeclareSubscriber {
id: 0, // @TODO use proper SubscriberId
wire_expr: res.expr().into(),
}),
},
res.expr(),
))
if face.whatami == WhatAmI::Client {
for mcast_group in &tables.mcast_groups {
if mcast_group.mcast_group != face.mcast_group {
mcast_group
.primitives
.send_declare(RoutingContext::with_expr(
Declare {
interest_id: None,
ext_qos: ext::QoSType::DECLARE,
ext_tstamp: None,
ext_nodeid: ext::NodeIdType::DEFAULT,
body: DeclareBody::DeclareSubscriber(DeclareSubscriber {
id: 0, // @TODO use proper SubscriberId
wire_expr: res.expr().into(),
}),
},
res.expr(),
))
}
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions zenoh/src/net/routing/hat/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,7 @@ impl HatBaseTrait for HatCode {
expr: &mut RoutingExpr,
) -> bool {
if src_face.id != out_face.id
&& match (src_face.mcast_group.as_ref(), out_face.mcast_group.as_ref()) {
(Some(l), Some(r)) => l != r,
_ => true,
}
&& (out_face.mcast_group.is_none() || src_face.mcast_group.is_none())
{
let dst_master = out_face.whatami != WhatAmI::Peer
|| hat!(tables).linkstatepeers_net.is_none()
Expand Down