session_manager: stop avatar session threads on remove_session - #616
Open
SkywalkerJeremy wants to merge 1 commit into
Open
session_manager: stop avatar session threads on remove_session#616SkywalkerJeremy wants to merge 1 commit into
SkywalkerJeremy wants to merge 1 commit into
Conversation
remove_session only dropped the dict reference, so a disconnected session's render/inference/frame-compositing/TTS threads kept running forever (~3 CPU cores per leaked session at idle). Set quit_event on removal so BaseAvatar.render() exits and cascades shutdown through the existing stop chain; flush_talk() first so no pending speech blocks the loop from noticing the event.
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.
Fixes #615.
remove_session()only dropped the dict reference (the# todo: 还可以主动调 avatar_session 释放spot), so after a peer disconnects, the session's render / inference / frame-compositing / TTS threads keep running forever — about 3 CPU cores per leaked session at idle, accumulating with every page refresh.The shutdown chain already exists:
BaseAvatar.render()exits onquit_eventand cascades stop/join to the other workers. This PR just triggers it on removal (flush_talk()first so pending speech doesn't delay the loop from noticing the event), wrapped in try/except so cleanup errors can't break session removal.Verified on our deployment (musetalk, webrtc, RTX 4090): after several connect/disconnect cycles, idle CPU dropped from ~324% to 0.0% and host load from 12.3 to 3.9; reconnecting afterwards works normally.