Skip to content

[core] Gate publisher sends by active connection layer - #2680

Merged
KerstinKeller merged 4 commits into
masterfrom
hotfix/dont-transmit-data-without-subscriber
Aug 19, 2026
Merged

[core] Gate publisher sends by active connection layer#2680
KerstinKeller merged 4 commits into
masterfrom
hotfix/dont-transmit-data-without-subscriber

Conversation

@KerstinKeller

@KerstinKeller KerstinKeller commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

This change tracks publisher connections and selected transport layers using atomic counters and explicit connection states. Writes now skip transport layers without active subscribers, reducing unnecessary data copies and network traffic while preserving zero-copy SHM where possible. Connection counts are updated incrementally instead of recalculated from the connection map. Transport counters are reset when writers are destroyed.

@KerstinKeller KerstinKeller added cherry-pick-to-support/v6.0 Cherry pick these changes to support/v6.0 cherry-pick-to-support/v6.1 Cherry pick these changes to support/v6.1 labels Jul 9, 2026
mutable std::mutex m_connection_map_mutex;
SSubscriptionMapT m_connection_map;
std::atomic<size_t> m_connection_count{ 0 };
std::atomic<bool> m_udp_send_enabled{ false };

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

instead of an std::atomic we should use connection counters, as we can increase / decrease them upon registration / unregistration which eliminates the need to iterate over the map every time.

@KerstinKeller

Copy link
Copy Markdown
Contributor Author

This is already better than what we had previously. However we still have a problem.
In theory we have a state machine for a connection: PENDING -> ESTABLISHED -> CLOSED. After the first regisration refresh a connection is pending, after the second refresh it's currently counted as establed. This is a very bad heuristic.

With this PR, we currently won't send out data for pending connections, which is a different behavior than previously.
We should consider modeling pending conditions as well, and already send data even if the connection has not yet been confirmed.

Anyways the logic is brittle, and what we need is a true handshake, as we get e.g. in TCP, instead of a heuristic via the monitoring.

Track the selected transport layer per subscriber connection and derive
per-layer send_enabled state so stale writer objects no longer emit data
after their last matching subscriber disconnects.
@KerstinKeller
KerstinKeller force-pushed the hotfix/dont-transmit-data-without-subscriber branch from 2f26a1c to faf3636 Compare August 18, 2026 13:26
// get payload buffer size (one time, to avoid multiple computations)
const size_t payload_buf_size(payload_.GetSize());

const bool udp_send_enabled = m_send_layer_connection_counters.UdpEnabled();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

already && with udp_writer.

@KerstinKeller
KerstinKeller merged commit 5a4bbf4 into master Aug 19, 2026
41 checks passed
KerstinKeller added a commit that referenced this pull request Aug 19, 2026
…subscribers. (#2680)

Co-authored-by: Kerstin Keller <13848742+KerstinKeller@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-to-support/v6.0 Cherry pick these changes to support/v6.0 cherry-pick-to-support/v6.1 Cherry pick these changes to support/v6.1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants