Skip to content

fix: auto-rejoin voice on 4014/4015 websocket close - #253

Closed
connorjamessmith wants to merge 1 commit into
lavalink4net:devfrom
connorjamessmith:fix/connorjamessmith/issue-200-voice-auto-reconnect-4014
Closed

fix: auto-rejoin voice on 4014/4015 websocket close#253
connorjamessmith wants to merge 1 commit into
lavalink4net:devfrom
connorjamessmith:fix/connorjamessmith/issue-200-voice-auto-reconnect-4014

Conversation

@connorjamessmith

@connorjamessmith connorjamessmith commented May 8, 2026

Copy link
Copy Markdown
Contributor

Problem

When Discord forces a gateway reconnect (observed with DSharpPlus nightly), Lavalink can emit a WebSocketClosedEvent for the voice websocket with close code 4014 (and sometimes 4015). After this happens, Lavalink reports the player as connected: false and, today, Lavalink4NET only forwards the event to listeners without attempting recovery. In practice the bot can end up leaving voice and not reconnecting on its own.

What This PR Changes

This PR adds an automatic recovery path inside LavalinkPlayer:

  • On remote voice websocket close codes 4014 (Disconnected) and 4015 (Voice server crashed), Lavalink4NET re-asserts the existing voice connection by re-sending a Discord voice state update to the current channel.
  • The rejoin uses the player’s configured SelfDeaf/SelfMute.
  • A cooldown is applied to avoid rejoin loops if Discord keeps closing the connection.
    Behavior change:
  • Recovery is enabled by default; set EnableVoiceAutoReconnect = false to preserve the previous behavior.
    New options:
  • LavalinkPlayerOptions.EnableVoiceAutoReconnect (default: true)
  • LavalinkPlayerOptions.VoiceReconnectCooldown (default: 10s)

Tests

Adds unit tests covering:

  • Rejoin attempt on 4014 and 4015
  • Opt-out disables recovery
  • Cooldown prevents repeated attempts
  • Cooldown behavior is thread-safe under concurrent close events

Refs #200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant