Skip to content

fix(rtc): don't block subscribe and unsubscribe while FfiQueue delivers - #892

Open
swayamg20 wants to merge 1 commit into
livekit:mainfrom
swayamg20:fix/888-ffiqueue-lock
Open

swayamg20 wants to merge 1 commit into
livekit:mainfrom
swayamg20:fix/888-ffiqueue-lock

Conversation

@swayamg20

Copy link
Copy Markdown
Contributor

Summary

FfiQueue.put held _lock for the whole delivery, so subscribe and unsubscribe, which every FFI request calls from its event loop, waited until the FFI callback thread had run every filter and call_soon_threadsafe.

  • subscribe and unsubscribe replace the subscriber list instead of mutating it, so put iterates without _lock, as suggested in the issue
  • A separate _put_lock keeps concurrent puts serialized, so every subscriber still sees events in the same order

Closes #888

Testing

  • uv run pytest tests/rtc/test_ffi_queue.py tests/rtc/test_room_ffi_filter.py -q -W error
  • uv run mypy livekit-protocol livekit-api livekit-rtc
  • uv run ruff check . and uv run ruff format --check .

Scope

unsubscribe no longer waits for an in-flight put, so that put can still deliver its item to the removed queue.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FfiQueue.put holds the subscriber lock across call_soon_threadsafe, so subscribe/unsubscribe on other event loops wait for the whole delivery

1 participant