Repository navigation
fix(rtps): a late joiner gets in ahead of re-announcing evictees on an oversubscribed domain - #907
Merged
Merged
Conversation
…n oversubscribed domain On a domain that stays bigger than the remote-participant pool, the eviction of unused participants starved the one participant the device needed: with one eviction per announcement period for anyone, the crowd's rejected members re-announce every period and take turns displacing each other at the eviction rate, and a participant never seen before competes with all of them for that one slot per period. In the QEMU suite the late /qemu_rx publisher went unmatched for 90 s (31 evictions, every victim "56 s since discovery") once the whole crowd of 28 was up against 20 usable slots; the passing runs had started the publisher while the crowd was still coming up. RecentEvictions, a ring of the participants evicted lately (one entry per pool slot, no allocation), decides whether an announcing participant may have one evicted for it: evicted less than SPDP_EVICT_READMIT_HOLDOFF_MS ago (default 5 x SPDP_RESEND_PERIOD_MS) -> held off, nothing evicted for it (it still takes a free slot at once); a former evictee past its hold-off -> the cooldown of one eviction per period, as before; never evicted -> served at once, cooldown or not (it is new only once, so the churn stays bounded). The victim selection is unchanged. Kconfig RTPS_SPDP_EVICT_READMIT_HOLDOFF_MS + the CMake knob pass-through; a host test pins the rule and the ring. The QEMU case lets the crowd settle 20 s after the first eviction before the publisher starts, so it meets a domain that STAYS bigger than the pool. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
|
✅Static analysis result - no issues found! ✅ |
… points by const reference cppcheck (useStlAlgorithm, passedByValue) on #907. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
rtps memory footprint (QEMU, esp32)Deltas in parentheses are against main @ 5b8ab2a (run 43628772840): a bigger size or a smaller free heap than the baseline's is a cost of this change. librtps.a in the image (bytes,
|
| embedded | host | host_large | |
|---|---|---|---|
| flash code | 156,354 (+1,077) | 157,873 (+1,139) | 158,243 (+1,107) |
| flash data | 1,268 (+0) | 1,268 (+0) | 1,268 (+0) |
| DRAM (.data + .bss) | 120 (+0) | 120 (+0) | 120 (+0) |
| IRAM | 0 (+0) | 0 (+0) | 0 (+0) |
engine objects, sizeof (bytes; the Domain is allocated from the heap at start())
| object | embedded | host | host_large |
|---|---|---|---|
| rtps::Domain (holds every pool below) | 98,992 (+392) | 568,296 (+3,136) | 3,149,544 (+12,544) |
| rtps::Participant | 34,096 (+392) | 42,528 (+392) | 52,512 (+392) |
| rtps::StatefulWriter | 2,528 (+0) | 2,960 (+0) | 6,416 (+0) |
| rtps::StatelessWriter | 1,872 (+0) | 2,256 (+0) | 3,792 (+0) |
| rtps::StatefulReader | 1,968 (+0) | 2,008 (+0) | 2,104 (+0) |
| rtps::StatelessReader | 1,960 (+0) | 2,000 (+0) | 2,096 (+0) |
| espp::RtpsParticipant | 608 (+0) | 608 (+0) | 608 (+0) |
embedded: heap by stage (free bytes; a cost is a negative delta)
| stage | internal | delta | internal low-water mark | largest internal block | PSRAM | delta |
|---|---|---|---|---|---|---|
| boot | 220,567 (-256) | 217,492 (-276) | 131,072 | 4,191,540 (+0) | ||
| started | 159,719 (-7,140) | -60,848 | 158,140 (-7,164) | 73,728 | 4,091,048 (+0) | -100,492 |
| endpoints | 138,923 (-7,764) | -20,796 | 136,560 (-7,764) | 69,632 | 4,091,048 (+0) | +0 |
embedded: heap after each host-driven step (free bytes; deltas against the previous row; the pools are preallocated, so a peer costs little heap - the low-water mark shows the transients)
| step | internal | delta | internal low-water mark | largest internal block | PSRAM | delta |
|---|---|---|---|---|---|---|
| baseline | 132,839 (-8,576) | 128,992 (-7,828) | 69,632 | 4,091,048 (+0) | ||
| +1 remote participant (no match) | 132,715 (-8,580) | -124 | 124,204 (-8,740) | 69,632 | 4,091,048 (+0) | +0 |
| +1 more remote participant (no match) | 132,695 (-8,572) | -20 | 123,936 (-8,984) | 69,632 | 4,091,048 (+0) | +0 |
| +1 remote participant with a matched publisher | 132,663 (-8,568) | -32 | 121,416 (-9,960) | 69,632 | 4,091,048 (+0) | +0 |
| after a service call | 132,639 (-8,580) | -24 | 94,032 (-9,888) | 69,632 | 4,091,048 (+0) | +0 |
| after an action goal | 131,583 (-8,588) | -1,056 | 79,716 (-12,048) | 69,632 | 4,091,048 (+0) | +0 |
| after one 30 KB sample | 131,575 (-8,600) | -8 | 74,684 (+644) | 69,632 | 4,060,836 (+0) | -30,212 |
| all peers gone | 131,575 (-8,604) | +0 | 74,684 (+644) | 69,632 | 4,060,836 (+0) | +0 |
host: heap by stage (free bytes; a cost is a negative delta)
| stage | internal | delta | internal low-water mark | largest internal block | PSRAM | delta |
|---|---|---|---|---|---|---|
| boot | 219,335 (-256) | 216,260 (-256) | 131,072 | 4,191,540 (+0) | ||
| started | 129,683 (-9,600) | -89,652 | 127,620 (-10,108) | 69,632 | 3,552,420 (-65,540) | -639,120 |
| endpoints | 109,335 (-9,416) | -20,348 | 106,972 (-9,416) | 69,632 | 3,617,960 (+0) | +65,540 |
host_large: the participant did not start on this target - the profile does not fit (panicked while the engine was being built - internal RAM exhausted building the Domain's mutexes (the first error logged: [RtpsTransport/E][3.169]: Failed to create valid UDP socket for port 7401)); its sizeof is in the table above, the boot heap below
host_large: heap by stage (free bytes; a cost is a negative delta)
| stage | internal | delta | internal low-water mark | largest internal block | PSRAM | delta |
|---|---|---|---|---|---|---|
| boot | 219,335 (-256) | 217,624 (-256) | 131,072 | 4,191,540 (+0) | ||
| started | n/a | |||||
| endpoints | n/a |
The QEMU memory suite on 1791df0 (run); the full numbers are the run's rtps-memory artifact.
…he engine tasks' stack margin The first CI run of the eviction hold-off passed the hardened late-joiner case and then crashed in the CycloneDDS pass: "A stack overflow in task rtps_worker_0", right after an eviction warning. The only addition on that path was a second formatted log (debug level, never printed) in the same frame - a few hundred bytes - so the 6144-byte worker stack had less margin than that. A receive worker runs the engine's deepest path (SPDP in -> eviction -> SEDP removal -> warning) and every reader and matched callback on top. - The held-off message is a PARTICIPANT_LOG (compiled out): nothing new is formatted on a worker. - THREAD_POOL_READER_STACKSIZE on ESP: 6144 -> 8192 in the three profiles (workers + reactor; the memory comment shows the cost against main). - The QEMU firmware's status line reports stack_min= / stack_min_task=, the smallest stack high-water mark over the engine's tasks (rtps_* and the action servers' exec_* workers) since boot (CONFIG_FREERTOS_USE_TRACE_FACILITY for uxTaskGetSystemState; the firmware's own publish timer is renamed so it does not count), and the harness gains device_stack_margin: at least 512 bytes, so a thin margin fails CI before it is a crash on a device. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
…newest evictions Review of #907 found two holes in "a never-evicted peer is served at once": the ring (one slot per pool entry, overwritten by slot order) can forget a peer still inside its hold-off once evictions run faster than one per period - which the bypass itself allows, up to N per 3 periods - and a forgotten peer passes as a first-timer, so a crowd bigger than the ring becomes a self-sustaining conveyor at that rate; and every eviction armed the one cooldown, so a stream of fresh GUIDs (ros2 CLI tools, restarting nodes) could starve a former evictee the device has since grown a reader for. Now two budgets of one eviction per period, each with its own clock: one for participants this one remembers evicting (past their hold-off), one for participants never evicted. The newcomer the device needs competes only with other first-timers, former evictees only with each other, and the churn is at most two per period. The ring overwrites the OLDEST EVICTION when full and is sized from the hold-off (2 * HOLDOFF / PERIOD + 2, capped at 64) so no peer still held off is ever forgotten. A newcomer already in the pool (the builtin-proxies call site) is never its own victim, whatever SPDP_EVICT_MIN_AGE_MS is. Stale "one per period" wording updated. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
…ers' own stack margin; floor 1024 Review of #907: the first eviction does not prove the crowd is up (leftovers of earlier cases fill the pool too), and the eviction count during settling was printed, not asserted - a run with the publisher starting mid-crowd still passed silently. Now the case waits for at least 8 evictions since the crowd launched (28 against 20 usable slots) and records that as pool_full_crowd_complete, and requires the publisher's samples within 40 s (CI: 14 s) so a slow conveyor cannot pass. The status line adds stack_min_worker= (the receive workers alone: they run user callbacks on the engine's deepest path and are the task that overflowed) beside the global minimum, and the device_stack_margin floor is 1024 bytes: one formatted log is about 500 bytes of buffer plus frames. First measured run: 1748 bytes (rtps_reply_hold), 2108 (rtps_protocol), the workers above that at 8192 - under 60 bytes at the old 6144. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
…as done The execute callback decremented the "executing" counter and then called canceled(); the test waits for the counter to reach 0 and asks get_result, which could see CANCELING instead of CANCELED (the Jazzy interop job did, once, on a commit that changed no engine code). Terminate first. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On a domain that stays bigger than the remote-participant pool, the eviction of unused participants (#895) could starve the one participant the device actually needs. Seen in CI on #906 (run 43622667460, firmware identical to main):
pool_full_evicts_unused_for_late_joinerwith the whole crowd of 28 up against 20 usable slots evicted one participant every 2-3 s for 90 s (31 evictions, each victim "56 s since discovery") and the late/qemu_rxpublisher was never matched. The passing runs of the case had started the publisher while the crowd was still coming up, so they never met the real scenario.Why: with one eviction per announcement period for anyone, the crowd's rejected members re-announce every period and take turns displacing each other at the eviction rate - a conveyor. A participant never seen before competes with all of them for the one slot per period and can lose every round.
Fix (
RecentEvictions, a ring of the participants evicted lately, one entry per pool slot, no allocation):SPDP_EVICT_READMIT_HOLDOFF_MSago (default 5 xSPDP_RESEND_PERIOD_MS: 10 s embedded, 5 s host; KconfigRTPS_SPDP_EVICT_READMIT_HOLDOFF_MS) gets nothing evicted for it when it announces again - it is unused, and it still takes a free slot at once;The victim selection is unchanged (an expired participant first, else the oldest-discovered one no user endpoint of ours matches, never one younger than
SPDP_EVICT_MIN_AGE_MS). A held-off announcement is not logged (aPARTICIPANT_LOG, compiled out, see below); evictions keep their warning.Found on the way, fixed here too - the receive workers' stack margin. The first CI run of this branch passed the hardened case (11 evictions while the crowd settled, the publisher's samples after 6 s) and then crashed in the CycloneDDS pass:
A stack overflow in task rtps_worker_0, right after an eviction warning. The only addition on that path was a second (debug-level, not even printed) formatted log in the same frame - a few hundred bytes - so the 6144-byte worker stack had less margin than that on main. A receive worker runs every reader and matched callback, i.e. user code, on top of the engine's deepest path (SPDP in -> eviction -> SEDP removal -> warning). So:PARTICIPANT_LOG), nothing new is formatted on the worker;THREAD_POOL_READER_STACKSIZEon ESP goes 6144 -> 8192 in the three profiles (the workers and the reactor: 3 tasks, 6 KB more internal RAM; the memory comment below shows the cost against main);stack_min=/stack_min_task=, the smallest stack high-water mark over the engine's tasks (rtps_* and the action servers' exec_* workers) since boot, andstack_min_worker=for the receive workers alone (the tasks that run user callbacks); the harness gainsdevice_stack_margin: at least 1024 bytes (one formatted log is ~500 bytes of buffer plus frames), so a thin margin fails CI before it becomes a crash on a device. Measured (matrix, final head): the receive workers' own margin is 2300 bytes at 8192 - i.e. about 250 bytes at the old 6144, which is the crash; the smallest over all engine tasks was 1748 bytes (rtps_reply_hold) in one run and 2104 (rtps_protocol) in another. Memory comment: the embedded profile's internal RAM atstartedis 7,148 bytes lower than main's (3 x 2 KB of stacks plus the trace facility's task-status memory).Harness: the QEMU case now waits until the crowd is provably complete - at least 8 evictions since its launch (28 against 20 usable slots), recorded as its own result
pool_full_crowd_completeso a run that could not exercise the scenario fails visibly instead of passing trivially - and requires the publisher's samples within 40 s (CI: 14 s), so a partially regressed conveyor cannot pass.Changes
rtps/discovery/RecentEvictions.hpp(new): the ring and the admissiongate()(Proceed / HeldOff / Cooldown).Participant::evictUnusedRemoteParticipant(newcomer, evicted, reason): takes the announcing participant; consults the gate underm_mutex, notes the victim after a successful removal. Both SPDP call sites pass the newcomer's prefix.SPDP_EVICT_READMIT_HOLDOFF_MSin the three limits profiles, Kconfig (int, under the eviction bool) and the CMake tuning-knob pass-through; Kconfig help of the eviction bool updated.pc/tests/rtps_recent_evictions.cpp: the rule (unknown peer served during the cooldown, held off within the hold-off, cooldown-bound past it, free after; a second eviction refreshes the entry; the ring overwrites its oldest slot and keeps the newest N).run_qemu_interop.sh+ interop README rows (the case, the new health gate);rtps_qemu.cppstatus line +CONFIG_FREERTOS_USE_TRACE_FACILITY=yforuxTaskGetSystemState; worker stack 8192 in the profiles and the component README.Review round 1 (independent reviewers)
Embedded/test-quality review: the 512-byte floor was below one formatted log (-> 1024, after the first measured margins); the global minimum hid the workers' own figure (->
stack_min_worker=); the harness precondition anchored on the first eviction, which leftovers of earlier cases can trigger, and printed rather than asserted the crowd (->pool_full_crowd_complete); the pass window of 90 s would have accepted a slow conveyor (-> 40 s). Follow-ups noted, not done here: the reactor does not need the worker stack (its receive handler runs on the pool), and logging the eviction off the receive worker would be the structural fix for that path's depth.Correctness review: (1) the first version served never-evicted peers at once with no budget, and the ring, overwritten by slot order, could forget a peer still inside its hold-off once evictions ran faster than one per period - a crowd bigger than the ring became a self-sustaining conveyor at up to N per 3 periods; (2) every eviction armed the one cooldown, so fresh GUIDs could starve a former evictee the device now needs; (3) with
SPDP_EVICT_MIN_AGE_MSforced to 0 the newcomer could select itself as victim at the builtin-proxies call site; (4) stale "one per period" / "6144" text. All four fixed in78fa027f5(two budgets, oldest-eviction overwrite + hold-off-derived ring size, self-victim guard, text). Verified fine by the reviewer: lock discipline (every ring access underm_mutex, SPDP -> SEDP -> Participant order), time arithmetic, the stack unit (IDF'sStackType_tisuint8_ton Xtensa and RISC-V, so the figure is bytes), the task-name filter, the harness gate's use of the minimum-since-boot.Verification
rtps_recent_evictionsPASS; the lib builds with the change.pool_full_crowd_complete(8 evictions, crowd complete after 22 s),pool_full_evicts_unused_for_late_joiner(the publisher's samples after 6 s, 4 evictions meanwhile) anddevice_stack_margin(2104 bytes, receive workers 2300); soak 10/10; memory suite green with the deltas above. An earlier head: matrix 38/38 with the publisher's samples after 14 s.🤖 Generated with Claude Code
https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU