Repository navigation
fix(rtc): reject async callbacks in EventEmitter.once - #903
Open
NabiBukhsh-AI wants to merge 1 commit into
Open
NabiBukhsh-AI wants to merge 1 commit into
NabiBukhsh-AI wants to merge 1 commit into
Conversation
NabiBukhsh-AI
requested review from
changt,
cloudwebrtc,
lukasIO and
xianshijing-lk
as code owners
October 26, 2026 08:10
This branch has not been deployed
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
EventEmitter.on()rejects coroutine functions,functools.partial(async_fn), andunittest.mock.AsyncMockby raising:However,
EventEmitter.once()wrapped the provided callback in a synchronous wrapper (once_callback) and passed it toself.on(), bypassing the check entirely.When an async callback was registered via
emitter.once(event, async_fn)or@emitter.once(event):emit(),once_callbackinvoked the async callback and received a coroutine object.once_callbackis synchronous, the returned coroutine was never awaited and was dropped with a PythonRuntimeWarning: coroutine '...' was never awaited.Changes
_check_async_callback(callback, method_name)to validate callbacks consistently across bothon()andonce()._ASYNCIO_COROUTINE_MARKER), andAsyncMockwith a descriptiveValueError.Testing
Added unit tests in
tests/rtc/test_emitter.py:test_once_rejects_async_callback: rejects direct async callbacks,functools.partial(async_fn), and@emitter.oncedecorated async functions.test_once_rejects_sentinel_tagged_callback: rejects callbacks tagged with_ASYNCIO_COROUTINE_MARKER.test_once_rejects_async_mock: rejectsunittest.mock.AsyncMock.uv run pytest tests/rtc/test_emitter.py -v -W error(15/15 passed)uv run ruff check livekit-rtc/livekit/rtc/event_emitter.py tests/rtc/test_emitter.py(passed)uv run ruff format --check livekit-rtc/livekit/rtc/event_emitter.py tests/rtc/test_emitter.py(passed)uv run mypy livekit-rtc/livekit/rtc/event_emitter.py tests/rtc/test_emitter.py(0 issues)