zenoh icon indicating copy to clipboard operation
zenoh copied to clipboard

Race condition in downsampling rules with multiple matches

Open ciandonovan opened this issue 2 months ago • 1 comments

Describe the bug

  downsampling: [
    {
      messages: [ "push" ],
      rules: [
        { key_expr: "*/thermal_image/sensor_msgs::msg::dds_::Image_/*", freq: 10 },
        { key_expr: "**/sensor_msgs::msg::dds_::Image_/*", freq: 1 },
      ],
    },
  ],

I want to apply a general downsample to /sensor_msgs::msg::dds_::Image_, but to exclude the topic here thermal_image and apply a looser downsampling rule.

In either order of which rule is first, there is a race condition where sometimes the general rule is applied to thermal_image, but sometimes the specific rule is correctly applied.

I'd like to see the rules being applied deterministically, where it is documented behaviour that either the first or the last rule match applies.

To reproduce

Configure a local Zenoh router on the target machine with the above configuration snippet.

Use a bridging router to connect the target Zenoh router to your local machine, below is an out-of-the-box example.

podman run -it --init --pull=newer --tz=local --ipc=host --net=host --dns=127.0.0.53 --volume="/tmp/:/tmp/:rw" --env RUST_LOG=warn,zenoh_transport::unicast::establishment=debug docker.io/eclipse/zenoh:1.5.1 --cfg='listen/endpoints:[]' --cfg='connect/endpoints:["tcp/localhost:7447","tcp/192.168.1.10:7447"]' --cfg='scouting/multicast/enabled:false' --cfg='transport/shared_memory/enabled:true' --cfg='transport/unicast/max_links:3'

Restart the target Zenoh router a number of times, observe the local subscriber's frequency, watch it be sometimes 1 Hz sometimes 10 Hz for that session at random.

System info

  • Platform: Offical DockerHub ROS 2 Jazzy images
  • Zenoh version: 1.5.1

ciandonovan avatar Oct 14 '25 19:10 ciandonovan

Hello @ciandonovan,

I think the correct behavior in this case is that both rules should apply to the message. The rules of downsampling basically mean to allow a maximum frequency under a key-expression, and since the rule applies to the key-expression as a whole rather than individual matches, it should apply both rules here, and therefore only allow the message through if both rules are not saturated.

@DenisBiryukov91 @sashacmc what do you think?

oteffahi avatar Nov 25 '25 09:11 oteffahi