fix(mqtt-neighbors): budget the JSON pool separately from the publish buffer

ArduinoJson v7 hands out document-pool blocks in fixed 4096-byte chunks, so
the pool is not bounded by the size of the text it serialises to. Budgeting
it at NEIGHBORS_JSON_BUFFER_SIZE starved it once the table grew: a 50-entry
table needs 12541 B of pool against the 10240 B cap, and a starved allocator
sets doc.overflowed(), which makes buildNeighborsMessage return 0 and drop
the entire publish rather than truncating the tail.

Repeaters with roughly 40 or more neighbours therefore published no neighbors
message at all, silently, while smaller tables published normally.

Give the pool its own NEIGHBORS_DOC_POOL_BUDGET and add an explicit
NEIGHBORS_MAX_PUBLISH_ENTRIES cap alongside the existing text-size check.
This commit is contained in:
agessaman committed 2026-08-03 10:29:32 -07:00
1 parent 37444be7b5
commit 34037f202d
3 files changed
+16 -4

No files matched your search

+3 -2
View File
@@ -1826,7 +1826,8 @@ bool MyMesh::completeNeighborDiscoverEntry() {
size_t added = MQTTMessageBuilder::measureNeighborsMessageEntry(measured);
if (neighbor_discover_publish_count > 0) added++; // array comma
if (neighbor_discover_json_size + added >= MQTTBridge::NEIGHBORS_JSON_BUFFER_SIZE) {
if (neighbor_discover_json_size + added >= MQTTBridge::NEIGHBORS_JSON_BUFFER_SIZE ||
neighbor_discover_publish_count >= MQTTBridge::NEIGHBORS_MAX_PUBLISH_ENTRIES) {
neighbor_discover_truncated = true;
finishNeighborDiscover();
return false;
@@ -1910,7 +1911,7 @@ static bool neighborPublishEntryComesBefore(
// single-shot doc (overflow path removes+breaks, so no further growth after free).
struct NeighborsDocAllocator : ArduinoJson::Allocator {
size_t used = 0;
static const size_t kBudget = MQTTBridge::NEIGHBORS_JSON_BUFFER_SIZE;
static const size_t kBudget = MQTTBridge::NEIGHBORS_DOC_POOL_BUDGET;
void* allocate(size_t size) override {
if (used >= kBudget || size > kBudget - used) return nullptr;