Pace configuration-packet sends to avoid device UDP buffer overrun#191
Merged
Conversation
Bulk per-channel setChannelConfig() bursts (e.g. Orion clearing LNC and spike processing on every channel — hundreds of datagrams back-to-back) overran the device's small UDP receive buffer (~8 CHANINFO packets), dropping packets including a following runlevel sync barrier, so sync() returned "Response timeout" and channel configuration failed. Older firmware (observed on a Gemini Hub, fw 7.7.0) is most affected; newer firmware drains fast enough to mask it, so it looked like a backward-compat regression. DeviceSession::sendPacket() now enforces a 200us minimum gap between consecutive configuration-channel sends (chid & cbPKTCHAN_CONFIGURATION). Data/streaming packets and isolated config sends (where the gap has already elapsed) are unaffected. sendPackets() already documented and paced its own batches; this extends that protection to the per-packet path callers use. Adds ConfigSends_ArePaced_DataSends_AreNot regression test (uses sleep_for's guaranteed-minimum semantics, so it can't be flaky) and a ClearConfigRepro example that reproduces the failure against real hardware. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
Configuring a device via Orion (Observatory) failed on a Gemini Hub running firmware 7.7.0 with repeated
Response timeouton the runlevel sync barrier, and channel configuration never completed:Root cause (verified on real Hub1 hardware)
Not a protocol issue — the Hub negotiates protocol 4.1. Orion's clear-config phase sends one
setChannelConfig()per channel (272 channels × 2 = ~544 UDP datagrams) back-to-back with no pacing, then callssync(). That burst overruns the device's small UDP receive buffer (~8 CHANINFO packets — the exact limitDeviceSession::sendPackets()already documents), dropping packets including the runlevel sync barrier, sosync()times out.Newer firmware drains fast enough to survive the burst, which is why this looked like a 7.7.0 backward-compat regression.
Reproduced and fixed on hardware: unpaced → times out every retry; with pacing → clear-config + sync succeeds on the first attempt (3/3 runs).
Fix
DeviceSession::sendPacket()enforces a 200 µs minimum gap between consecutive configuration-channel sends (chid & cbPKTCHAN_CONFIGURATION). Data/streaming packets and isolated config sends (gap already elapsed) incur no delay. This extends the pacing thatsendPackets()already does for its own batches to the per-packet path that callers use — so it protects every caller with no change required in Orion.Testing
ConfigSends_ArePaced_DataSends_AreNot— usessleep_for's guaranteed-minimum semantics, so the timing assertion cannot be flaky.examples/ClearConfigRepro/clear_config_repro.cppreproduces the failure against real hardware (clear_config_repro HUB1, envPACE=<n>to compare).cbdev_device_tests/cbdev_tests/cbsdk_testspass. (ConnectionParams_Predefined_NPlayfails onmastertoo — pre-existing, unrelated.)🤖 Generated with Claude Code