HIGH: Voice Session Leaks - Unclosed Discord Audio Connections #4
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What the Problem Is
When a user joins a voice channel and the bot creates a voice connection, the connection is not properly cleaned up if the bot crashes, is stopped forcefully, or encounters an error. Each leaked voice connection holds a WebSocket connection to Discord and can accumulate.
Where It Occurs
bot/voice_manager.py#L120-L125- Voice session trackingbot/voice_manager.py#L200-L210- Connection lifecyclebot/bot.py#L300-asyncio.create_task(join_voice_channel())without cleanup handlerbot/bot.py#L454-asyncio.create_task(leave_voice_channel())without cleanup handlerWhy This Is a Problem
What Can Go Wrong
Scenario 1: Bot Crashes During Voice Session
Scenario 2: User Joins Multiple Channels
Proposed Fix
1. Implement Voice Session Tracking and Cleanup
2. Register Cleanup on Bot Shutdown
Severity
HIGH - Voice session leaks prevent bot from connecting to voice channels after crashes; ghost connections confuse users.
Files Affected
bot/utils/voice_manager.py, bot/bot.py, bot/command_router.py
Addressed in commit
8d51370as part of the graceful shutdown implementation. The new graceful_shutdown() function explicitly calls VoiceSessionManager.end_session() as its first step, which properly disconnects from voice, releases GPU locks, cleans up audio resources, and stops STT processing. This prevents ghost voice connections after bot restart.