Skip to content

fix(rtps): the QEMU restart case no longer runs the device out of internal RAM - #922

Merged
finger563 merged 1 commit into
mainfrom
fix/rtps-qemu-restart-memory
Nov 22, 2026
Merged

finger563 merged 1 commit into
mainfrom
fix/rtps-qemu-restart-memory

Conversation

@finger563

Copy link
Copy Markdown
Contributor

Description

The RTPS interop QEMU matrix (qemu (matrix)) has failed on main since #909. Its 33 failures are one problem.

The restart case tears the device's participant down and builds a new one, while about a dozen peers from the earlier cases are still announcing. The new participant discovers them all at once. Two things then took the byte-addressable internal RAM that a task stack needs:

  • the discovery proxies, which are small allocations and so go to internal RAM first
  • lwIP's receive and reassembly buffers, which are internal-only by default

The firmware's publish timer then could not create its task. std::thread failed with pthread: Failed to create task!, which aborts because exceptions are off. The device rebooted, QEMU's emulated chip cannot boot again after a software reset, and every later case failed with it.

The cause, from the uploaded device log and a backtrace decoded against a local build of the same firmware (app_main → espp::Timer → espp::Task::start → std::thread → abort):

stage internal free, first boot internal free, after the restart
boot 220 KB (largest 128 KB) 220 KB (largest 68 KB)
participant started 159 KB 160 KB
endpoints created 139 KB 75 KB, most of it 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 allocates from PSRAM first.
    • CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=65536: twice the default is kept for allocations that must be internal, such as FreeRTOS stacks and DMA.
  • Diagnostics: the memory markers and the status line also report dram= / dram_min= / dram_largest= (MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT, where a stack comes from). The existing internal figure includes IRAM, which is what hid the shortage. The new fields are appended, so the memory suite's name=<digits> parser is unaffected.

How has this been tested?

  • The firmware builds (sdkconfig.defaults;sdkconfig.ci.defaults, IDF 6.1), and both settings are in the generated sdkconfig.
  • The QEMU matrix needs the ROS 2 stacks and runs in CI only; this PR's run is the test.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation Update
  • Hardware (schematic, board, system design) change
  • Software change

Checklist:

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • I have updated the documentation accordingly.
  • I have updated the .github/workflows/build.yml file to add my new test to the automated cloud build github action.
  • All new and existing tests passed.
  • My code follows the code style of this project.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU

…ernal RAM

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.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DFjjnq3XCTRAXENSxsCxJU
@github-actions

Copy link
Copy Markdown

✅Static analysis result - no issues found! ✅

@github-actions

Copy link
Copy Markdown

rtps memory footprint (QEMU, esp32)

Deltas in parentheses are against main @ e80f55a (run 45033145457): a bigger size or a smaller free heap than the baseline's is a cost of this change.

librtps.a in the image (bytes, idf.py size-components)

embedded host host_large
flash code 162,072 (-4) 163,430 (-8) 163,846 (+0)
flash data 1,272 (+0) 1,272 (+0) 1,272 (+0)
DRAM (.data + .bss) 126 (+0) 126 (+0) 126 (+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) 99,208 (+0) 569,968 (+0) 3,156,208 (+0)
rtps::Participant 34,304 (+0) 42,736 (+0) 52,720 (+0)
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,279 (-264) 218,168 (+700) 131,072 4,191,440 (-100)
started 160,371 (+908) -59,908 159,800 (+2,620) 73,728 4,090,192 (-856) -101,248
endpoints 139,791 (+908) -20,580 138,416 (+1,892) 69,632 4,090,192 (-856) +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 133,255 (+432) 130,860 (+1,800) 69,632 4,090,224 (-824)
+1 remote participant (no match) 133,123 (+420) -132 126,360 (+2,324) 69,632 4,090,224 (-824) +0
+1 more remote participant (no match) 133,119 (+464) -4 125,872 (+1,836) 69,632 4,090,224 (-824) +0
+1 remote participant with a matched publisher 133,091 (+464) -28 123,300 (+1,856) 69,632 4,090,224 (-824) +0
after a service call 133,075 (+464) -16 98,280 (+3,000) 69,632 4,090,224 (-824) +0
after an action goal 132,019 (+480) -1,056 83,728 (-520) 69,632 4,090,224 (-824) +0
after one 30 KB sample 132,015 (+476) -4 75,960 (+1,308) 69,632 4,060,012 (-824) -30,212
all peers gone 132,015 (+484) +0 75,960 (+1,308) 69,632 4,060,012 (-824) +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,047 (-264) 216,936 (+700) 131,072 4,191,440 (-100)
started 130,459 (+372) -88,588 129,676 (+1,168) 69,632 3,617,120 (-840) -574,320
endpoints 109,915 (+624) -20,544 108,540 (+1,608) 69,632 3,617,120 (-840) +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][2.779]: 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,047 (-264) 218,320 (+720) 131,072 4,191,440 (-100)
started n/a
endpoints n/a

The QEMU memory suite on eaf6716 (run); the full numbers are the run's rtps-memory artifact.

@finger563
finger563 merged commit 555cdd3 into main Nov 22, 2026
28 checks passed
@finger563
finger563 deleted the fix/rtps-qemu-restart-memory branch November 22, 2026 19:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant