Clean up failed voice connections

This commit is contained in:
2026-06-22 12:18:35 +02:00
parent d10dae1b53
commit b29fda5ae9
2 changed files with 12 additions and 5 deletions
+7
View File
@@ -89,7 +89,14 @@ export default class AudioManager {
});
this.connection.subscribe(this.audioPlayer);
try {
await entersState(this.connection, VoiceConnectionStatus.Ready, this.options.connectTimeoutMs);
} catch (error) {
this.connection.destroy();
this.connection = undefined;
this.playbackState = 'stopped';
throw error;
}
this.playbackState = 'ready';
this.scheduleRenewal();
}
+4 -4
View File
@@ -101,7 +101,7 @@ describe('AudioManager', () => {
expect(mockAudioPlayer.play).toHaveBeenCalledWith(mockAudioResource);
});
it('keeps failed connection startup observable', async () => {
it('cleans up when connection startup fails', async () => {
jest.useFakeTimers();
const manager = new AudioManager({
@@ -112,10 +112,10 @@ describe('AudioManager', () => {
await expect(manager.connect()).rejects.toThrow('voice connection timeout');
expect(manager.state).toBe('connecting');
expect(manager.isConnected).toBe(true);
expect(manager.state).toBe('stopped');
expect(manager.isConnected).toBe(false);
expect(mockConnection.subscribe).toHaveBeenCalledWith(mockAudioPlayer);
expect(mockConnection.destroy).not.toHaveBeenCalled();
expect(mockConnection.destroy).toHaveBeenCalledTimes(1);
expect(jest.getTimerCount()).toBe(0);
});