Repository navigation
fix(rtc): send and receive data packets without a new ctypes array type - #912
Merged
Merged
Conversation
publish_data built a `ctypes.c_byte * data_len` array type for each new payload length, and the data packet receive path did the same with `ctypes.POINTER(ctypes.c_byte * data_len)`. Each ctypes array type is a reference cycle, so every packet of a new length left garbage that only the cyclic garbage collector can free. Pass the address of the bytes payload directly on the send side, and read the received buffer with ctypes.string_at, as FfiClient.request already does.
zek
requested review from
changt,
cloudwebrtc,
lukasIO and
xianshijing-lk
as code owners
October 28, 2026 18:29
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Closes #911.
publish_dataand the data packet receive path built actypes.c_byte * data_lenarray type for each new payload length. On Python 3.12 and 3.13 the receive side keeps these types alive for the life of the process (thectypes.POINTER()cache holds them). On Python 3.14 each type is cyclic garbage.bytespayload withget_address. The native library copies the data during the request, as fix(rtc): pass the FFI request bytes without a new ctypes array type #847 already relies on inFfiClient.request. This also removes the per-byte(*payload)unpack.ctypes.string_at, asFfiClientdoes for event buffers.The new test
test_publish_data_makes_no_ctypes_array_typesends 10 payloads of new lengths, waits for the receiver to get them, and makes sure that no array type with these lengths exists. It also makes sure that the received payloads are intact.Before and after
repro.pyfrom #911, against a local LiveKit server (v1.13.5). The "this branch" rows use the branch source with the native library from the livekit 1.2.0 wheel:gc.collect(): 0, array types still alive: 100gc.collect(): 1300, array types still alive: 0Tests (
livekit-rtc/tests/test_dc.py):test_publish_data_makes_no_ctypes_array_typetest_dc.pyandtest_ffi_client.pytests