Repository navigation
fix: buffer out-of-order inbound packets instead of dropping them - #203
Conversation
AckRequest packets were only accepted when they were exactly the next id; anything ahead of sequence was dropped. After a single lost/reordered packet, the ATEM retransmits its unacked window once per frame in bursts that contain only one packet we can accept, while also sending a new Time packet every frame. We therefore advance by one packet per frame, equal to the arrival rate, so the backlog never drains and every state change adds to it permanently (acks ~22 packets behind, growing latency, each packet resent 7-8x) until the session is reconnected. Packets up to 256 ids ahead of sequence are now buffered (duplicates ignored), and drained in order once the gap is filled. A drain acks immediately so the ATEM stops retransmitting the window. The buffer is cleared on a new session, reconnect and disconnect. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review. WalkthroughAtemSocketChild buffers eligible out-of-order inbound AckRequest packets and delivers them in sequence when gaps close. It reconnects when a gap remains stalled for the connection timeout, even if other packets arrive. It clears buffered packets on session and connection changes. ChangesInbound packet sequencing
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to The change buffers eligible out-of-order packets and reconnects on stalled gaps. No actionable merge-blocking issue is established; merge after normal checks pass. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to The buffer improves recovery from reordered traffic, but it also lets an unvalidated sender place packets into a future delivery window. Those packets could later replace legitimate device updates. Memory bounds and session cleanup limit the impact, while actual network exposure remains unknown. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
About the Contributor
This pull request is posted on behalf of Bitfocus (Bitfocus Buttons / Companion, which uses
atem-connectionthrough thebmd-atemmodule). Contact: @erlendjones.Type of Contribution
This is a: Bug fix
Current Behavior
AtemSocketChild._receivePacketonly accepts an AckRequest packet if it is exactlylastReceivedPacketId + 1. Any packet that arrives ahead of sequence is silently dropped.Over VPN the responsiveness gets bogged down. A single lost or reordered packet is enough to push the connection into a backlog it never recovers from:
Timepacket every frame, even without timecode being requested.PrgI/PrvI/tally after a cut) adds to the backlog permanently.We confirmed this on a live ATEM reached over a VPN:
New Behavior
restartConnectionand disconnect.Testing Instructions
yarn unit. There are 6 new tests insocket-child.spec.ts, and all of them fail onmain:mainthe backlog stays at exactly 22 packets for every frame; with this change it drains to 0.Other Information
We tested the same logic against a live ATEM over VPN, patched into the
atem-connectionbundled in bmd-atem 3.20.1. The backlog stayed at ~0 while cutting, where before it grew with every cut.Status
🤖 Generated with Claude Code