Repository navigation
Conversation
Incoming data streams were rebuilt from the low-level stream_header/chunk/ trailer events. Since livekit-ffi 0.15.0 always advertises data streams v2, other SDKs send C++ participants single-packet and deflate-compressed streams, which that path can't read: inline streams hang readAll() forever and compressed chunks arrive as raw deflate bytes. It also appended duplicate chunks, never reported length, gap or close-reason errors, and left streams open when a participant disconnected. The FFI also handed C++ an owned reader handle for every incoming stream, which C++ ignored, so every stream's content stayed buffered in the FFI for the life of the process. - Room consumes text/byte_stream_opened: unhandled topics drop the reader handle; handled topics start read_incremental and route the resulting *_stream_reader_events (keyed by reader handle) to the reader. The low-level stream_*_received events are now ignored. - Readers surface abnormal ends (sender close reason, length mismatch, missed chunk, size limit, disconnect) as DataStreamError, which derives from std::runtime_error, after draining buffered chunks. They merge end-of-stream attributes into info() on the reading thread and gain close(); ByteStreamReader gains readAll() to match TextStreamReader. - Room shutdown wakes blocked readers with a "Disconnected while receiving" error. - Readers warn when they would block on the FFI callback thread. TextStreamOpenedEvent / ByteStreamOpenedEvent::reader_handle was never populated and stays 0; it is now documented as deprecated. Writers are unchanged: the FFI readers still accept the v1 packets they send. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ports the rest of the Rust incoming-manager tests a v1 (multi-packet, uncompressed) sender can reproduce: too few / too many bytes against total_length, duplicate chunks, chunk gaps, trailer reasons, orphan packets, remote writers that close with a reason or the wrong length, and sender or receiver disconnects mid-stream. All 12 fail without the previous commit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ports the Rust incoming-manager tests for data streams v2 as other SDKs send them: inline streams (compressed and uncompressed, empty, large but highly compressible), multi-packet compressed text and byte streams, UTF-8 reframing of decompressed text, and text streams with attachments. All 10 fail without the FFI reader port: inline streams are never delivered and compressed chunks arrive as raw deflate bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ports the Rust incoming-manager closer tests through TextStreamReader::close(): closing ends an open stream once, discards queued chunks, spares a later stream that reuses the id, and is harmless after disconnect. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 30, 2026
Author
|
CI for this branch (manually dispatched, since |
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.
Part 2 of 5 of the data streams v2 stack. Merge in order; each part is mergeable on its own.
sendText/sendBytes/sendFileByteStreamReader::writeToFileand a receive size limitstreamText/streamBytesThis stack replaces #321, #322 and #325 (same code, reordered so each step stands on its own).
Fixes receiving data streams from every other LiveKit SDK. This changes no public API beyond small additions:
DataStreamError,reader->close(), andByteStreamReader::readAll().The bug
Since livekit-ffi 0.15.0, every FFI client advertises data streams v2. So Python, Node, JS, Rust and Swift send C++ participants single-packet ("inline") and deflate-compressed streams. The C++ SDK rebuilt incoming streams from the low-level
stream_header/chunk/trailerevents, and that path:readAll()hung);The FFI also handed C++ an owned reader handle for every incoming stream, which C++ ignored. So each stream's content stayed buffered in the FFI for the life of the process.
The fix
Roomconsumestext/byte_stream_opened:read_incrementaland routes the*_stream_reader_events to the reader.DataStreamErrorwhen a stream ends abnormally, after returning the chunks already received.DataStreamErrorderives fromstd::runtime_error. Abnormal ends include a close reason, a length mismatch, a missed chunk, the size limit, or a disconnect.close(), and log a warning if they would block on the FFI callback thread.ByteStreamReadergainsreadAll()to matchTextStreamReader.*StreamOpenedEvent::reader_handlewas never filled in (it was always 0). It is now documented as deprecated.Behaviour change: a stream that ends abnormally used to look complete, handing back silently truncated data. It now throws.
Nothing gets more broken: writers are unchanged and still send v1 packets, which the FFI readers accept, so C++-to-C++ streams keep working.
Tests
On the parent branch (and
main), 22 of the 27 receive conformance tests fail:With this PR, all pass.
test_data_stream_conformance_receive_v1.cpptest_data_stream_conformance_receive_v2.cpptest_data_stream_conformance_receive_api.cppreader->close()teststest_data_streams.cppclose()waking a read, reader handles releasedtest_data_stream.cpp(unit)Rust
incoming/manager.rstests covered hereLIVEKIT_TOKEN_C)Not portable end to end; the Rust crate's own tests cover these:
StreamClosedevents, and internal-topic filtering.The size-limit tests come in part 4.
Verification (local, macOS arm64,
livekit-server --dev)livekit1.3.0 → C++: a short and a 50 KBsend_textarrived intact in 3/3 runs. Onmain, 0/3: neither stream arrives.main,bugprone-exception-escapeon~Room. The tool traces a possiblestd::length_errorthrough theLK_LOG_ERRORin its catch block.~Roomitself is unchanged, the check is not error-level, and the same code passed CI's clang-tidy 19 on Data streams: receive via FFI readers; add sendText / sendBytes / sendFile #321.DataTrackE2ETestschema tests (DefineAndGetSchema,DefineAndGetCustomSchemaEncoding,DefineDuplicateSchemaFails). They fail onmainon this machine too, and the 1 skip is the token-server test.🤖 Generated with Claude Code