Fix for incremental reader chunk-drop#259
Merged
MaxHeimbrock merged 2 commits intomainfrom Apr 27, 2026
Merged
Conversation
Exercise ReadIncrementalInstructionBase<T>.OnChunk with several chunks arriving before the consumer drains, simulating multiple ChunkReceived events delivered on the same sync-context flush. The base keeps only a single _latestChunk, so earlier chunks are silently overwritten; the test pins this down ahead of the queue-backed fix on a follow-up branch. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ReadIncrementalInstructionBase<T> previously stored each incoming chunk in a single _latestChunk field. When several ChunkReceived FFI events were dispatched on the same sync-context flush (routine between Unity frames), OnChunk overwrote the field before the consumer coroutine could resume from its yield, silently dropping earlier chunks. Queue chunks that arrive while a prior read is still pending. Reset() advances _latestChunk to the next queued chunk and keeps IsCurrentReadDone true so the next yield completes immediately, draining the buffer before waiting for more FFI events. Flips DataStreamIncrementalReadTests from failing to passing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2e92fe4 to
f01d5b6
Compare
ladvoc
approved these changes
Apr 27, 2026
| [Test] | ||
| public void OnChunk_MultipleChunksBeforeConsumerDrains_AllChunksAreObserved() | ||
| { | ||
| using var handle = new FfiHandle(IntPtr.Zero); |
Contributor
There was a problem hiding this comment.
question: I'm probably missing something obvious, but how does creating a zero FfiHandle work here?
Contributor
Author
There was a problem hiding this comment.
It is a null pointer and we just need it to satisfy the constructor. In the TestIncrementalReader we can push chunks to mock callbacks without needing any native stuff, so the null handle is never used. Does that answer your question?
Contributor
Author
There was a problem hiding this comment.
And on cleanup we check if the handle is valid, so it would also not be released.
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.
Summary
ReadIncrementalInstructionBase<T>.OnChunkcall into a single_latestChunkfield, so when severalChunkReceivedFFI events are dispatched on the same sync-context flush (common: multiple chunks arriving between Unity frames), earlier chunks are silently overwritten before the consumer coroutine can resume from its yield.Test plan
Add just the new unit test without the fix and see the CI tests fail:
https://github.com/livekit/client-sdk-unity/actions/runs/24781354985?pr=259
Fix bug in 2nd commit will make this test go green without changing the test itself.