Skip to content
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

[Bug]: Error when streaming audio for a long time #2762

Open
3 tasks done
josago97 opened this issue Aug 14, 2023 · 2 comments
Open
3 tasks done

[Bug]: Error when streaming audio for a long time #2762

josago97 opened this issue Aug 14, 2023 · 2 comments
Labels
bug Needs investigation Needs to be looked at by a maintainer

Comments

@josago97
Copy link
Contributor

Check The Docs

  • I double checked the docs and couldn't find any useful information.

Verify Issue Source

  • I verified the issue was caused by Discord.Net.

Check your intents

  • I double checked that I have the required intents.

Description

There is a problem with streaming audio when you are streaming for a long time. Using the audio streaming tutorial as an example, if you broadcast a radio station instead of streaming a file, a series of errors occur over the course of several hours, canceling and blocking a future stream. After transmission hours an error occurs The remote party closed the WebSocket connection without completing the close handshake. This error is followed by The server sent close 4006: "Session is no longer valid." After these errors, if you try to reconnect to the voice channel using the voiceChannel.ConnectAsync() method, it throws the System.TimeoutException: 'The operation has timed out' error, which prevents you from reconnecting until you restart the bot.

Version

3.12.0

Working Version

No response

Logs

# START BOT
[General/Info] 03:39:23 Discord     Discord.Net v3.12.0 (API v10)
[General/Info] 03:39:23 Gateway     Connecting
[General/Info] 03:39:24 Gateway     Connected
Ready
[General/Info] 03:39:25 Gateway     Ready

# PLAYING RADIO
[General/Info] 03:39:37 Audio #1    Connecting
[General/Warning] 03:39:37 Audio #1    Unknown OpCode (Hello)
[General/Warning] 03:39:37 Audio #1    Unknown OpCode (18)
[General/Warning] 03:39:37 Audio #1    Unknown OpCode (20)
[General/Info] 03:39:38 Audio #1    Connected
[General/Warning] 04:37:14 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
[General/Info] 04:37:14 Gateway     Disconnecting
[General/Info] 04:37:14 Gateway     Disconnected
[General/Info] 04:37:15 Gateway     Connecting
[General/Info] 04:37:15 Gateway     Connected
[General/Info] 04:37:15 Gateway     Resumed previous session
[General/Warning] 06:43:55 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
[General/Info] 06:43:55 Gateway     Disconnecting
[General/Info] 06:43:55 Gateway     Disconnected
[General/Info] 06:43:56 Gateway     Connecting
[General/Info] 06:43:56 Gateway     Connected
[General/Info] 06:43:56 Gateway     Resumed previous session
[General/Warning] 10:23:50 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
[General/Info] 10:23:50 Gateway     Disconnecting
[General/Info] 10:23:50 Gateway     Disconnected
[General/Info] 10:23:51 Gateway     Connecting
[General/Info] 10:23:51 Gateway     Connected
[General/Info] 10:23:51 Gateway     Resumed previous session
[General/Warning] 12:13:12 Audio #1    Unknown OpCode (18)
[General/Warning] 12:13:12 Audio #1    Unknown OpCode (20)
[General/Warning] 12:22:59 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
[General/Info] 12:22:59 Gateway     Disconnecting
[General/Info] 12:22:59 Gateway     Disconnected
[General/Info] 12:23:00 Gateway     Connecting
[General/Info] 12:23:01 Gateway     Connected
[General/Info] 12:23:01 Gateway     Resumed previous session
[General/Warning] 12:56:18 Audio #1    System.Exception: WebSocket connection was closed
 ---> System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake.
   at System.Net.WebSockets.ManagedWebSocket.ThrowIfEOFUnexpected(Boolean throwOnPrematureClosure)
   at System.Net.WebSockets.ManagedWebSocket.EnsureBufferContainsAsync(Int32 minimumRequiredBytes, CancellationToken cancellationToken, Boolean throwOnPrematureClosure)
   at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
   at System.Net.WebSockets.ManagedWebSocket.ReceiveAsyncPrivate[TResult](Memory`1 payloadBuffer, CancellationToken cancellationToken)
   at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
   at System.Threading.Tasks.ValueTask`1.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---
   at Discord.Net.WebSockets.DefaultWebSocketClient.RunAsync(CancellationToken cancelToken)
   --- End of inner exception stack trace ---
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
[General/Info] 12:56:18 Audio #1    Disconnecting
[General/Info] 12:56:18 Audio #1    Disconnected
[General/Info] 12:56:19 Audio #1    Connecting
[General/Warning] 12:56:19 Audio #1    Unknown OpCode (Hello)
[General/Error] 12:56:19 Audio #1    System.Exception: WebSocket session expired
 ---> Discord.Net.WebSocketClosedException: The server sent close 4006: "Session is no longer valid."
   at Discord.Net.WebSockets.DefaultWebSocketClient.RunAsync(CancellationToken cancelToken)
   --- End of inner exception stack trace ---
   at Discord.ConnectionManager.WaitAsync()
   at Discord.Audio.AudioClient.OnConnectingAsync()
   at Discord.ConnectionManager.ConnectAsync(CancellationTokenSource reconnectCancelToken)
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
[General/Info] 12:56:19 Audio #1    Disconnecting
[General/Info] 12:56:19 Audio #1    Disconnected
# END PLAY RADIO

[General/Warning] 14:17:48 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
[General/Info] 14:17:48 Gateway     Disconnecting
[General/Info] 14:17:48 Gateway     Disconnected
[General/Info] 14:17:49 Gateway     Connecting
[General/Info] 14:17:49 Gateway     Connected
[General/Info] 14:17:49 Gateway     Resumed previous session
[General/Warning] 16:45:28 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
[General/Info] 16:45:28 Gateway     Disconnecting
[General/Info] 16:45:28 Gateway     Disconnected
[General/Info] 16:45:29 Gateway     Connecting
[General/Info] 16:45:29 Gateway     Resumed previous session
[General/Info] 16:45:29 Gateway     Connected
[General/Info] 16:48:41 Audio #2    Connecting
# TRYING CONNECT TO VOICE CHANNEL FAILED WITH ERROR:
System.TimeoutException: 'The operation has timed out.'
   at Discord.WebSocket.SocketGuild.<ConnectAudioAsync>d__334.MoveNext()
   at Discord.WebSocket.SocketGuild.<ConnectAudioAsync>d__334.MoveNext()
   at Discord.WebSocket.SocketVoiceChannel.<ConnectAsync>d__24.MoveNext()
   at DiscordBot.Logic.Audio.Bueno.Models.Player.<EnsureVoiceChannelAsync>d__38.MoveNext()

Sample

No response

Packages

.NET 6

Environment

Windows 10 Pro x64 22H2 19045.3324
.NET 6.0.21

@josago97 josago97 added the bug label Aug 14, 2023
@josago97 josago97 changed the title [Bug]: [Bug]: Error when streaming audio for a long time Aug 14, 2023
@DeclanFrampton
Copy link
Contributor

DeclanFrampton commented Aug 31, 2023

I am assuming this would close the PR #2765 correct? @josago97

If so, link this bug within the PR with closes tag and if/when PR is approved this will also be closed.

@josago97
Copy link
Contributor Author

josago97 commented Sep 2, 2023

No, that PR doesn't solve this problem. When I was trying to solve this problem I noticed that the discord heartbeat was not being used and that is why I made the PR. As I have been testing, I think this problem has to do with a bad connection closure, in such a way that when it reconnects it gives an error due to residue from the previous disconnection.

@Misha-133 Misha-133 added the Needs investigation Needs to be looked at by a maintainer label Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Needs investigation Needs to be looked at by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants