Repository navigation
Controller: refuse a device it runs out of memory on, instead of aborting - #38
Merged
Merged
Conversation
…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
This was referenced Nov 14, 2026
Merged
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.
With exceptions enabled, as on the ESP32, a failed
newof a discovered device'sDevice,NodeorPropertythrewstd::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(), fromDevice::addNodePropertiesFromConfigJson()(homie/src/Device.cpp:39) viacreate_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
$descriptionis rejected:out of memory building device <id> ...; it is not tracked);$descriptions are ignored without a log line.What was built stays allocated until
controller_reset(), becauseDevicedoes not free its nodes and properties.Device::addNodePropertiesFromConfigJson()returnsfalseon such a failure, and the newDevice::out_of_memory()reports it.Device::addNode()'s node-limit refusal is unchanged.Tests:
test_controller_out_of_memory. It replaces the global nothrowoperator newso it fails on demand, and covers three cases:$description;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