fix: RangeError flood when the MSE staging buffer overflows - #2381
Open
paolostivanin wants to merge 1 commit into
Open
fix: RangeError flood when the MSE staging buffer overflows#2381paolostivanin wants to merge 1 commit into
paolostivanin wants to merge 1 commit into
Conversation
video-rtc.js buffers incoming websocket frames into a fixed 2 MiB Uint8Array while the SourceBuffer is busy, and drains it on updateend. Two gaps make that wedge permanently: - if the drain's appendBuffer throws (QuotaExceededError is the common one, when a mobile browser backgrounds the tab and the decoder stops evicting), the exception is swallowed and bufLen is never reset. No update cycle was started, so updateend never fires again and the drain is never re-entered. - ondata then always takes the buffering branch, and buf.set(b, bufLen) has no bounds check. Once bufLen passes 2 MiB it throws "RangeError: offset is out of bounds" on every frame that arrives, at stream frame rate, until the socket closes. Observed as ~150 errors/second reported back to the server by Home Assistant's frontend error reporter. Reset bufLen when the drain fails, and bound-check the staging append, dropping the backlog and restarting the update cycle so the stream can resync on the next keyframe.
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.
video-rtc.js buffers incoming websocket frames into a fixed 2 MiB Uint8Array while the SourceBuffer is busy, and drains it on updateend. Two gaps make that wedge permanently:
Observed as ~150 errors/second reported back to the server by Home Assistant's frontend error reporter.
Reset bufLen when the drain fails, and bound-check the staging append, dropping the backlog and restarting the update cycle so the stream can resync on the next keyframe.