Socket events that don't fit the static buffer are logged and not sent. The state events are small (shadeState is about 400 bytes), but remoteFrame lists up to 300 pulse timings and real frames already came to 1.8-2.1 KB against the 2 KB buffer. MAX_SOCK_RESPONSE is now 4096 in SocketEmitter.h, and a static_assert next to remoteFrame fails the build if 300 pulses of 10 digits no longer fit. KNOWN_ISSUES.md closes the entry with the bounds of every event. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8.7 KiB
Known Issues
Concurrent mutation during chunked /controller response
Status: fixed: reads in step 2, edits in step 3; command replies still read the live model (below).
Introduced: 2026-04-19, alongside the chunked-response conversion of /controller (the original crash report was about cbuf::resize aborting async_tcp).
Fixed: 2026-10-16, steps 2 and 3 of LOOP_QUEUE_PLAN.md.
What it was
The chunked /controller response read somfy.rooms, somfy.shades, somfy.groups and somfy.repeaters on async_tcp a piece at a time as the client's TCP window opened, for hundreds of ms to seconds. Anything that changed them meanwhile could make the document contradict itself: a deleted shade in shades but not in a group's linkedShades, two positions for one shade, a linked shade skipped or written twice. /discovery, /shades and the other reads had the same exposure, only shorter.
All eight read routes (/controller, /discovery, /rooms, /shades, /groups, /room, /shade, /group) now stream a ModelSnapshot that loop() fills, so each document describes one moment (ADR-0002). That is fix option (c), taken per read in a heap slot of about 5.6 KB.
Edits (step 3)
The handlers that changed the shade model on the web server task (adding, saving and deleting rooms, shades and groups; linking remotes, repeaters and group members; /setPaired; the sort orders) now hand the edit to loop() through the LoopQueue, and every client learns the result from a requestResult socket event. So /linkRemote can no longer race a received frame for a linked remote's rolling code: both now change it on loop(), in the order they happen.
Still open
- Command replies (
/shadeCommand,/tiltCommand,/unpairShade,/setRollingCode, ...) still copy the one item they report from the live shade model on async_tcp, so a reply can show a value from the middle of a change./room,/shade,/groupand/groupOptionsalso check on the live model whether the item exists, because the status goes out before the snapshot is filled. - The read routes leave out an item that doesn't fit their 3 KB unit, see Oversized read items are left out.
Oversized read items are left out
Status: open
Location: SnapshotWriter::overflowed in src/ModelSnapshot.cpp.
Summary
Every read route builds each room, shade, group and linked shade into a 3 KB unit before sending it. When one doesn't fit, the writer logs an ESP_LOGE line, skips that item and carries on, so the document stays valid JSON. The client gets no sign that anything is missing: the item just isn't in the list. Before step 2 only /controller did this; /discovery, /shades and the rest grew their buffer instead.
A shade with every linked remote populated is about 1.5 KB today, so nothing overflows yet. It becomes a silent loss as soon as a change to the shade, room or group fields pushes an item past 3 KB.
Concrete failure modes
- A shade is left out after a firmware change adds fields to it. It is missing from the config UI, and Home Assistant doesn't create an entity for it.
- A group whose
linkedShadesentry doesn't fit loses that shade from its list.
Fix options (pick one later)
- (a) Fail loud. Add a list of the skipped item ids to the end of the document, and show a warning in the UI.
- (b) Check the size at build time. Work out the worst case for each item from the field limits and
static_assertthat it fits the buffer, so a change that breaks it doesn't build.
Related
- The same "lost without telling the client" problem as Large websocket events are dropped.
Large websocket events are dropped
Status: fixed (fix option (c)): the buffer is 4 KB, and the largest event provably fits.
Location: JsonSockEvent in src/WResp.cpp, buffer g_response[MAX_SOCK_RESPONSE] (now 4096 bytes, defined in src/outputs/SocketEmitter.h).
Summary
Socket events are built into one static buffer. When a value doesn't fit, JsonSockEvent::_safecat marks the event as overflowed, and endEvent logs an error and doesn't send it. Clients never see malformed JSON. The event is simply lost, and the client isn't told.
Unlike the /controller HTTP crash, this path does not abort: there is no growing cbuf and no new[] on the send path.
What can be large
remoteFrame(the frame log) lists every pulse of a received frame: up toMAX_TIMINGS= 300. A pulse recorded while waiting for a sync has no upper bound, so in theory each can be 10 digits: 300 × 11 bytes plus about 300 bytes of fields is about 3.8 KB. Real frames come to 1.8–2.1 KB, which was already at the old 2 KB limit. Astatic_assertinTransceiver.cppfails the build ifMAX_TIMINGSor the buffer change so that it no longer fits.- The state events are small.
shadeStatehas about 20 fields and no linked remotes, about 400 bytes. (The 1.3–1.5 KB figure this entry used to give was for a shade with its linked remotes, which only the read routes send.)groupStatelists at most 32 shade ids.frequencyScan,memStatus,fwStatus,ethernetandrequestResulthave a few fixed fields each.
The 2 KB more of static RAM is the cost. The log line stays as a backstop.
Options that weren't taken
- (a) Fail loud: send a small error event in place of the dropped one so the client reloads the state.
- (b) Split large events across frames: the socket.io ack/chunk pattern, with matching client-side reassembly.
Related
- Not the same code path as the
/controllercrash. Solve independently. - Worth grepping for
JsonSockEventusages that iterate collections (see references inSomfyEvents.cpp,Transceiver.cpp,ESPNetwork.cpp,GitOTA.cpp) to identify the most at-risk events. - Group reads emit events from the web server task (fixed): a second task writing the same buffer.
Group reads emit events from the web server task
Status: fixed 2026-10-16, step 2 of LOOP_QUEUE_PLAN.md (fix option (a)). Read routes write from a ModelSnapshot, and the replies still written on async_tcp copy the group with snapshotGroup(), which works its flags out without changing the group or sending anything.
Location: serializeGroupRef in src/entryPoints/Web.cpp called SomfyGroup::updateFlags() in src/SomfyGroup.cpp.
Summary
Serializing a group for an HTTP reply first calls group->updateFlags(). When the group's flags no longer match its shades', that writes group->flags, sends a groupState socket event and publishes the group's MQTT topics, all on the async_tcp task, while loop() sends events and publishes too.
Every socket event is formatted into the one static buffer g_response in src/outputs/SocketEmitter.cpp through the one JsonSockEvent in sockEmit. Two tasks emitting at once write over each other's event. The MQTT client (PubSubClient) isn't safe to use from two tasks either.
Reached from every route that serializes a group: /controller, /discovery, /groups, /group, /groupCommand, /addGroup, /saveGroup, /linkToGroup, /unlinkFromGroup and others.
Concrete failure modes
- A
groupStatefrom a/groupsrequest and ashadeStatefromloop()are formatted at the same time: clients receive garbled JSON, or an event with another event's fields. - The group's MQTT publish interleaves with one from
loop()in the client's buffer, and the broker gets a broken packet or the connection drops. group->flagsis written on async_tcp whileloop()updates the same group throughupdateGroupFlags().
It needs a group whose flags are out of date at the moment a client reads it, for example right after a sensor frame changed a linked shade's sun or wind flags, so it is rare.
Fix options
- (a) Drop
updateFlags()from the serializers.loop()already keeps group flags current throughupdateGroupFlags(). This is part of step 2 of LOOP_QUEUE_PLAN.md: reads come from a ModelSnapshot thatloop()fills, and serializers only read. - (b) Only emit from
loop(). Covered by ADR-0002 once nothing outsideloop()changes the shade model.
Related
- ADR-0002: the loop task is the only writer of the shade model.
- Large websocket events are dropped: the same
g_responsebuffer.