microReticulum icon indicating copy to clipboard operation
microReticulum copied to clipboard

Memory leak on nRF52 (T114): heap pool exhausted every 1–2.5 h under announce load

Open Giak88 opened this issue 2 weeks ago • 1 comments

Board: Heltec Mesh Node T114 (nRF52840), env heltec_t114 from master (upstream firmware, no custom code), RNS_HEAP_POOL_BUFFER_SIZE=131072. Diagnostics: -DRNS_DEBUG_MEMORY -DRNS_DEBUG_METRICS -DRNS_DEBUG_HEAP.

Setup: the T114 is a LoRa transport node. A nearby rnsd (RNode, mode = gateway) is connected to a TCP backbone and rebroadcasts its announces over LoRa (a few hundred per hour).

Symptom: the node resets every ~80–160 min. Last lines before each reset: Reticulum::loop: bad_alloc Interface::handle_incoming: bad_alloc - out of memory Error occurred while validating announce ... std::bad_alloc ContainerAllocator failed to allocate memory (166–345 bytes)

Measurements (one line every 10 min, values from Heap Pool Stats / Default and Container Allocator Stats): time used maxfree dflt_active cntr_active cntr_bytes 03:08 74392 45156 820 309 11728 03:28 80948 34928 934 88 5671 03:48 93668 25812 1029 240 9568 04:08 105428 13380 1104 294 10965 04:28 111416 6492 1225 226 8701 (reset, then) 04:34 67732 53416 764 204 7909

  • Default allocator active count grows steadily (~300/h, ~88 bytes each on average); pool usage grows ~28 KB/h; rate depends on received traffic.
  • Container allocator is flat (cntr_bytes 6–13 KB), so it is not a growing vector/Bytes buffer.
  • All tables reported by RNS_DEBUG_METRICS stay bounded: paths 25 (cap), phl 50, ikd 50, dprt 8–49, annc 0–3, preqs/dpreqs/cdsts/chshs 0–2, revr/held/rcp/lt/pl/tun 0. They go up and down while the pool keeps falling.
  • _announce_rate_table is never erased, but announce_rate_target is 0 on the interface, so it should not be in use.

My guess: some ~88-byte object allocated with new (or a std::map/set/list node using the default allocator) per received announce/packet that is never freed. Same behaviour with my own firmware on top of master, so I tested plain heltec_t114 to rule my code out.

Happy to run any build or extra instrumentation you want.

Giak88 avatar Nov 14 '26 16:11 Giak88

New data in #113: with all three stores in RAM (RNS_PERSIST_PATHS/HASHLIST/KNOWN_DESTINATIONS=0, path and known capped at 50) the node has run 25 h without a reboot and the pool stays flat (largest free block ~16.9 KB for hours, dflt_active not growing). The growth seems tied to the FileStore persistence path rather than to transport itself. Leaving this open until the root cause is found.

Giak88 avatar Nov 19 '26 10:11 Giak88