New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cancel MediaRelay's consumer task when the last proxy is stopped #919
base: main
Are you sure you want to change the base?
Conversation
src/aiortc/contrib/media.py
Outdated
@@ -578,6 +578,10 @@ def _stop(self, proxy: RelayStreamTrack) -> None: | |||
# unregister proxy | |||
self.__log_debug("Stop proxy %s", id(proxy)) | |||
self.__proxies[track].discard(proxy) | |||
if len(self.__proxies[track]) == 0 and track in self.__tasks: | |||
self.__tasks[track].cancel() | |||
del self.__tasks[track] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather have the un-registration happen in a single place. Couldn't we handle cancellation in __run_track
?
This looks interesting but I don't see the corresponding unit test? |
01b49c1
to
5f0e87c
Compare
@@ -578,18 +578,24 @@ def _stop(self, proxy: RelayStreamTrack) -> None: | |||
# unregister proxy | |||
self.__log_debug("Stop proxy %s", id(proxy)) | |||
self.__proxies[track].discard(proxy) | |||
if len(self.__proxies[track]) == 0 and track in self.__tasks: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(self.__proxies[track]) == 0 and track in self.__tasks: | |
# stop worker if this was the last proxy | |
if not self.__proxies[track] and track in self.__tasks: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How can track
not be in self.__tasks
?
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #919 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 30 30
Lines 5816 5824 +8
=========================================
+ Hits 5816 5824 +8 ☔ View full report in Codecov by Sentry. |
One thing I'm wondering about: if you stop all the consumer, isn't data just going to build up indefinitely in the source track? |
Stop the
MediaRelay.__run_track()
task when all the downstream relay tracks are stopped.This is kind of optimization, not a bug fix.