Skip to content

Controller: refuse a device it runs out of memory on, instead of aborting - #38

Merged
dcj merged 1 commit into
mainfrom
fix/controller-out-of-memory
Nov 14, 2026
Merged

dcj merged 1 commit into
mainfrom
fix/controller-out-of-memory

Conversation

@dcj

@dcj dcj commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

With exceptions enabled, as on the ESP32, a failed new of a discovered device's Device, Node or Property threw std::bad_alloc, and nothing caught it, so the board aborted.

Found on a wESP32 (rev 8, no PSRAM) running esp32-firmware as a controller against a broker with about nine devices, including an AbleEdge bridge with two circuit children of about 40 properties each. It aborted on every boot, 10 to 20 s in, building the second circuit. The backtrace: operator new -> __cxa_throw -> std::terminate(), from Device::addNodePropertiesFromConfigJson() (homie/src/Device.cpp:39) via create_device_from_description().

The fix: these allocations now use new (std::nothrow).

  • A device the controller cannot allocate (find_or_create_device()) is not tracked, and the failure is logged.

  • A device it runs out of memory building from its $description is rejected:

    • the build stops at the first failure;
    • it is logged once (out of memory building device <id> ...; it is not tracked);
    • its property messages and repeat $descriptions are ignored without a log line.

    What was built stays allocated until controller_reset(), because Device does not free its nodes and properties.

  • Device::addNodePropertiesFromConfigJson() returns false on such a failure, and the new Device::out_of_memory() reports it.

  • Device::addNode()'s node-limit refusal is unchanged.

Tests:

Tracking only the devices a controller needs (by type) is #36; a configured budget is #37.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VUQ6asqTe3tYwnZR7GW2dn

…ting

With exceptions enabled, as on the ESP32, a failed new of a discovered
device's Device, Node or Property threw std::bad_alloc and nothing caught it.
On a wESP32 without PSRAM, a controller on a broker with an AbleEdge bridge
and two circuits aborted on every boot. These allocations now use
new (std::nothrow): a device the controller cannot allocate is not tracked,
and one it runs out of memory building from its $description is rejected,
logged once, and its messages ignored. Device::addNodePropertiesFromConfigJson()
returns false on such a failure and Device::out_of_memory() reports it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VUQ6asqTe3tYwnZR7GW2dn
@dcj
dcj merged commit 78125aa into main Nov 14, 2026
8 checks passed
@dcj
dcj deleted the fix/controller-out-of-memory branch November 14, 2026 19:21
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