Repository navigation
fix(rtps): a peer that restarts within its lease is rediscovered at once (GUID incarnation + dispose as the previous incarnation + SPDP restart detection) - #909
Merged
Conversation
A board's GUID prefix is MAC-based, so one that reboots within its lease comes back as the participant its peers still hold, with every writer numbering from 1 again. Best-effort readers drop a sequence number below the next they expect (RTPS 2.5 8.4.12.1) - the SPDP reader included - so the restarted board's announcements and samples were ignored until the lease sweep forgot the old incarnation (5 s for an ESP peer, 100 s for a host one). #900 only covered a stale announcement after a participant's own dispose. - GUID prefix bytes 10-11 are a per-boot incarnation (Domain::guidIncarnation, esp_random once per boot) instead of a constant: a rebooted board is a new participant to every stack, as RTPS requires. - The previous boot's incarnation survives a software reset in RTC memory (Domain::previousGuidIncarnation); the SPDP agent disposes that participant as its writer's first change (inline-QoS key hash + status info, GUID in the payload), so peers that still hold it drop it at once. The receiver honours such a dispose as the participant's own when the prefixes agree in bytes 0-9 and carry this engine's vendor id (other vendors use bytes 10-11 differently: Fast DDS keeps its in-process participant id there), and remembers it as newer than anything the old incarnation can still announce. - The SPDP reader is exempt from the ordering filter; an announcement from a known participant numbered at most half of its highest is a restart (SPDPAgent::isRestart): the participant is forgotten and rediscovered from that announcement (parsed again - the parser stops at the GUID of a known one). A single reordered or duplicated announcement never qualifies. - pc/tests/rtps_participant_restart.cpp drives all of it with hand-crafted datagrams; the QEMU firmware reboots on a "RESTART" sample and logs its incarnation, the CI defaults give it a 30 s lease, and the harness gains the restart cases against the ROS 2 subscriber/publisher (both rmws) and the espp host engine. Host suite 62/62; QEMU firmware builds with the CI defaults. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
|
✅Static analysis result - no issues found! ✅ |
…(cppcheck) 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 @ 939c5d8 (run 43653919456): 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 | 162,076 (+4,754) | 163,438 (+4,617) | 163,846 (+4,675) |
| flash data | 1,272 (+4) | 1,272 (+4) | 1,272 (+4) |
| DRAM (.data + .bss) | 126 (+6) | 126 (+6) | 126 (+6) |
| 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) | 99,208 (+216) | 569,968 (+1,672) | 3,156,208 (+6,664) |
| rtps::Participant | 34,304 (+208) | 42,736 (+208) | 52,720 (+208) |
| 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,543 (-24) | 217,468 (-24) | 131,072 | 4,191,540 (+0) | ||
| started | 159,691 (+0) | -60,852 | 158,112 (+20) | 73,728 | 4,091,048 (+0) | -100,492 |
| endpoints | 138,875 (-44) | -20,816 | 136,516 (-40) | 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,795 (-40) | 128,948 (-40) | 69,632 | 4,091,048 (+0) | ||
| +1 remote participant (no match) | 132,659 (-40) | -136 | 124,372 (-88) | 69,632 | 4,091,048 (+0) | +0 |
| +1 more remote participant (no match) | 132,627 (-24) | -32 | 124,348 (+4) | 69,632 | 4,091,048 (+0) | +0 |
| +1 remote participant with a matched publisher | 132,619 (-24) | -8 | 121,448 (-16) | 69,632 | 4,091,048 (+0) | +0 |
| after a service call | 132,583 (-48) | -36 | 94,100 (-1,192) | 69,632 | 4,091,048 (+0) | +0 |
| after an action goal | 131,515 (-60) | -1,068 | 78,512 (-2,656) | 69,632 | 4,091,048 (+0) | +0 |
| after one 30 KB sample | 131,507 (-60) | -8 | 73,892 (-784) | 69,632 | 4,060,836 (+0) | -30,212 |
| all peers gone | 131,511 (-44) | +4 | 73,892 (-784) | 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,311 (-24) | 216,236 (-24) | 131,072 | 4,191,540 (+0) | ||
| started | 130,071 (-16) | -89,240 | 128,472 (-16) | 69,632 | 3,617,960 (+0) | -573,580 |
| endpoints | 109,263 (-168) | -20,808 | 106,904 (-164) | 69,632 | 3,617,960 (+0) | +0 |
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.377]: 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,311 (-24) | 217,600 (-24) | 131,072 | 4,191,540 (+0) | ||
| started | n/a | |||||
| endpoints | n/a |
The QEMU memory suite on 273d5ef (run); the full numbers are the run's rtps-memory artifact.
…Domain incarnation; review fixes Review of the first revision: - The previous-incarnation dispose was sent from the NEW prefix naming the old participant. Cyclone DDS refuses an SPDP dispose whose source prefix is not the participant it names, and Fast DDS drops a non-ALIVE change from a writer it has not matched yet, so only espp peers honoured it. It is now a raw RTPS message AS the old incarnation (its prefix in the header, its SPDP writer, its participant GUID as key hash and payload, a sequence number above anything it sent), multicast on the first three announce cycles (SPDPAgent::sendPreviousIncarnationDispose). Every stack takes a participant's own dispose, so the receive-side relaxation for same-board prefixes, the SN-max dispose memory and the Writer friend declaration go. - The SPDP reader never holds writer proxies, so its exemption from the ordering filter was dead code; reverted, prose corrected everywhere. - The incarnation is drawn per Domain (constructor), not once per process: an application that recreates its Domain is a new participant too, and the QEMU firmware can restart its participant without rebooting the chip - QEMU's emulated chip panics inside ESP-IDF's startup (esp_timer interrupt allocation) after esp_restart, which took the first CI run's device down for the rest of the matrix. - The restart verdict is decided and recorded under the participant mutex (Participant::noteRemoteParticipantAnnouncement); isRestart rejects sequence number 0 and peers seen fewer than three times. - RTC_NOINIT_ATTR falls back to .noinit DRAM on chips without RTC memory. - Harness: RESTART is published for 6 s (a one-shot publisher raced the device's matching and never got through) and the new participant ignores it for its first 20 s; the ROS 2 daemon's publisher count on the device's topic now proves the old incarnation was dropped (restart_<rmw>_old_incarnation_dropped); results no longer share a flag; the RTC check is named for what it checks. - Docs: the power-cycle case expires with its lease (nothing to dispose); the fallback-prefix collision note; README rows. Host suite 60/60; QEMU firmware builds with the CI defaults. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
…rd to 5 s The first CI run of the restart cases showed the engine fix working on the cyclone pass (incarnation cur/prev, the daemon drops to one publisher at once) but the fastdds and espp-host cases failed at "the device did not take the RESTART": `ros2 topic pub --once -w 1` publishes a single reliable sample right after the match and does not reliably reach the device, and the firmware's 20 s ignore-guard was longer than the spacing between cases, so a just-restarted participant swallowed the next case's RESTART too. Publish RESTART at 2 Hz after the subscriber matches (`-w 1 -r 2`) and stop it the moment the device takes the restart, so the new participant gets no copy; the firmware ignore-guard drops to 5 s as a backstop for an in-flight duplicate. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
… sample The topic-based RESTART trigger was never reliably delivered on the fastdds pass (a single reliable sample to a freshly-matched reader, and even -r 2 to a new publisher participant, did not reach the device, while the cyclone pass won the timing). The restart now rides the already-matched /qemu_add_two_ints request/reply channel, which both RMWs proved reliable (the service case passes): a magic request (a=424242, b=0) restarts the participant after the reply goes out. The topic callback no longer carries the trigger. (The earlier -w1/-r2 harness change in this branch did not actually land - a multi-edit threw before writing - which is why the previous CI run repeated the failure.) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
…heck) cppcheck flagged the function-local kRestartMagicA/B as unread - it does not connect their use inside the nested service-handler lambda. At namespace scope the use is plain. No behaviour change. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
… recreate is fragile With the service-triggered restart delivering reliably, the FastDDS restart cases pass (incarnation rotates, the ROS 2 daemon drops the old participant at once, the previous incarnation is remembered and disposed) and so does the espp-host one. But the device "reboots" by recreating its espp participant in-process (a chip reset trips a QEMU startup bug), and doing that several times in one boot is not yet robust: after a couple of cycles the engine's teardown leaves a task that fires into freed state, the device panics, and QEMU cannot survive the reboot. That is a separate teardown-robustness follow-up, not the discovery fix under test. So the matrix restarts the device once, on the FastDDS pass - enough to prove a real DDS stack honours the standard participant dispose the device sends. The receive side for every peer (and the espp host engine) is covered by pc/tests/rtps_participant_restart.cpp. The per-rmw and espp-host restart cases are dropped. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
…ycloneDDS) The engine fix must be proven against CycloneDDS too, not only FastDDS. The last run showed two in-process participant recreates in one boot are stable (the FastDDS and espp-host restarts both passed); only a third crashed, from internal-RAM fragmentation as each recreate reallocates the engine's task stacks. So restart once on each rmw pass - FastDDS and CycloneDDS get a real peer to honour the device's dispose - and drop the redundant espp-host restart (the host test covers that side). The repeated-recreate fragmentation stays a separate teardown follow-up. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
The device "reboots" in QEMU by recreating its espp participant in-process (a chip reset trips a QEMU startup bug). That recreate frees and reallocates the engine's FreeRTOS task stacks in internal RAM and fragments it: the first recreate is reliable, but a second one eventually fails a stack allocation and the device aborts. Restarting once per rmw pass therefore crashed the device on the second (CycloneDDS) recreate, so the CycloneDDS dispose was never actually verified and device_no_crash failed. Do the restart exactly once for the whole run, on the FastDDS pass, with BOTH a FastDDS and a CycloneDDS peer watching that single restart. Each stack's own subscriber proves the new incarnation is accepted at once (its echo receives the restarted publisher's "qemu 0".. samples, daemon-independent), and each stack's ROS 2 daemon proves the dispose is honoured (publisher count on the device topic drops back to one within seconds instead of after the 30 s lease). The dispose checks also require the daemon to have seen the live publisher before the restart, so a daemon that never discovered cannot read as a trivial pass. Results are now restart_fastdds_rediscovered_by_ros2_sub, restart_cyclone_rediscovered_by_ros2_sub, restart_device_sub_receives, restart_fastdds_old_incarnation_dropped, restart_cyclone_old_incarnation_dropped and restart_previous_incarnation_remembered. The espp host engine's own handling of a restarted peer stays covered by pc/tests/rtps_participant_restart.cpp. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
The single restart now passes everything but restart_device_sub_receives: with both stacks watching, the device's own publisher is rediscovered instantly, so the rediscovery loop broke at 0 s and the reverse direction (the rebooted device receiving the across-restart ROS 2 publisher) was sampled before its new incarnation had re-matched that writer. Poll for it instead - the publisher stays up at 5 Hz, so the new reader fills in within seconds of re-match. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
2 of 12 tasks
finger563
added a commit
that referenced
this pull request
Nov 22, 2026
…ernal RAM (#922) The QEMU matrix has failed on main since #909: its restart case tears the participant down and builds a new one while a dozen peers from the earlier cases are still announcing. The new participant discovers them all at once: the proxies (small allocations, internal RAM first) and lwIP's receive / reassembly buffers (internal-only by default) took the byte-addressable internal RAM a task stack needs, so the firmware's publish timer could not create its task (std::thread -> "pthread: Failed to create task!" -> abort with exceptions off). The device rebooted, QEMU's emulated chip cannot boot again from a software reset, and every later case failed with it. From the device log: endpoints used ~20 KB of internal RAM at first boot but ~84 KB after the restart (internal free 139 KB vs 75 KB, most of the latter IRAM, which stacks cannot use). #909's own CI run passed: the case was at the edge of the budget. - sdkconfig.defaults: CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y (lwIP from PSRAM first) and CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=65536 (twice the default kept for allocations that need internal RAM: FreeRTOS stacks, DMA). - The memory markers and the status line also report dram= / dram_min= / dram_largest= (internal AND 8-bit: what a stack comes from), since `internal` includes IRAM and hid the shortage. Appended, so the memory suite's parser is unaffected. Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
A board that reboots within its lease comes back with the GUID prefix its peers still hold (the prefix is built from the MAC), and every one of its writers numbers its samples from 1 again. Its announcements only refresh the known participant's lease, the stateful readers keep waiting for the old numbers, and a best-effort reader ignores the restarted writer (RTPS 2.5 8.4.12.1), so nothing moved until the lease sweep forgot the old incarnation - 5 s for an ESP peer, 100 s for a host one - and the board was deaf and mute to that peer the whole time. Reported from the field, reproduced with a host stand-in. The dispose memory from #900 only covered a stale announcement arriving after a participant's own dispose; a reboot never sends one, and there was no test for it.
Fix (four layers, each tested)
A5 5Abefore) are a nonce drawn when the Domain is constructed (Domain::guidIncarnation()), so a rebooted board - or an application that recreates its Domain - is a new participant to every peer. That is what RTPS requires of a GUID, and what Fast DDS and Cyclone DDS need to see, since their readers apply the same best-effort rule.RTC_NOINIT_ATTR,.noinitDRAM on chips without RTC memory; magic + complement; survives a software reset, not a power cycle). On its first three announce cycles the SPDP agent sends a participant dispose for it the way every stack accepts one: an RTPS message whose header prefix and SPDP writer are the OLD incarnation's, naming its participant GUID in the inline-QoS key hash and the payload, numbered above anything that writer could have sent (SPDPAgent::sendPreviousIncarnationDispose). Cyclone DDS rejects an SPDP dispose whose source prefix differs from the participant it names and Fast DDS drops a non-ALIVE change from a writer it has not matched, so a dispose from the new prefix would not do; this form is a participant's own dispose, which the espp receiver already honoured and which needs no relaxation of the "only a participant's own writer may dispose it" rule.SPDPAgent::isRestart): the participant is forgotten and rediscovered from that announcement, under the participant mutex together with the lease refresh (Participant::noteRemoteParticipantAnnouncement), and the announcement is parsed again after the removal because the parser stops at the GUID of a known participant. A single reordered or duplicated announcement never qualifies, sequence number 0 never qualifies. This covers peers that do reuse a prefix - another stack deriving it from stable hardware identifiers; this engine's boards no longer do.pc/tests/rtps_participant_restart.cppdrives the receiving side with hand-crafted datagrams: a restarted peer's samples 1..3 are delivered again; a late announcement is not a restart; the previous incarnation's own dispose (old prefix, sequence number above its last) is honoured, the new incarnation is discovered and a stale old announcement is ignored; disposes from a stranger and from another prefix naming the peer are refused.RESTARTsample the firmware tears its participant down and creates a new one (a new incarnation; the previous one is read back from the RTC record and disposed) and logsRTPSTEST incarnation cur= prev=. A software reset of QEMU's emulated chip panics inside ESP-IDF's startup before any application code, so the chip is not rebooted; recreating the Domain is what a board's reboot looks like to its peers.sdkconfig.ci.defaultsgives the device a 30 s lease so a restart cannot hide behind lease expiry. New cases, per rmw:restart_<rmw>_rediscovered_by_ros2_sub(a ROS 2 subscriber that stays up across the restart receives the restarted publisher's first samples, "qemu 0".."qemu 9", within 25 s),restart_<rmw>_device_sub_receives(the ROS 2 publisher's samples reach the restarted device),restart_<rmw>_old_incarnation_dropped(the ROS 2 daemon, up throughout, counts one publisher on the device's topic again within 15 s - without the dispose it holds both for 30 s),restart_previous_incarnation_remembered(the RTC record), andrestart_espp_host_pub->device_subagainst the espp host engine. Documented ininterop/README.mdand the component README.Verification
set-target esp32,sdkconfig.defaults;sdkconfig.ci.defaults).rtps_qemujob); they cannot run locally on this machine. An independent review of the first revision found the dispose form above and the dead SPDP-reader exemption it replaced; both fixed in the second revision.No wire-format change: the prefix bytes were already arbitrary to peers, the dispose is the standard participant dispose, and the engine's own announcements are unchanged.
🤖 Generated with Claude Code
https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU