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]: Wrong report of AudioClient.ConnectionState #2973

Open
3 tasks done
Dragonox77 opened this issue Aug 1, 2024 · 3 comments
Open
3 tasks done

[Bug]: Wrong report of AudioClient.ConnectionState #2973

Dragonox77 opened this issue Aug 1, 2024 · 3 comments
Labels

Comments

@Dragonox77
Copy link

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

Hello,

When connecting to a voice channel (VoiceChannel.ConnectAsync) and wating for a while (multiple hours), the AudioClient.ConnectionState is not ConnectionState.Connected, but on Discord, I can see that the bot is still connected.

Maybe it's not the right method to check if the bot is connected to a discord voice channel ?

When I read logs, it seems like if the websocket connection is closed there is not log saying "Resumed previous session" this is maybe something to investigate ?

Thank you.

Version

3.15.3

Working Version

No response

Logs

2024-07-30 00:55:15,687 [11] INFO  Discord.NET - 00:55:15 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 00:55:15,687 [11] INFO  Discord.NET - 00:55:15 Gateway     Disconnecting
2024-07-30 00:55:15,687 [11] INFO  Discord.NET - 00:55:15 Gateway     Disconnected
2024-07-30 00:55:16,688 [11] INFO  Discord.NET - 00:55:16 Gateway     Connecting
2024-07-30 00:55:17,191 [11] INFO  Discord.NET - 00:55:17 Gateway     Resumed previous session
2024-07-30 00:55:17,191 [11] INFO  Discord.NET - 00:55:17 Gateway     Connected
2024-07-30 02:51:05,237 [3] INFO  Discord.NET - 02:51:05 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 02:51:05,237 [3] INFO  Discord.NET - 02:51:05 Gateway     Disconnecting
2024-07-30 02:51:05,238 [3] INFO  Discord.NET - 02:51:05 Gateway     Disconnected
2024-07-30 02:51:06,239 [3] INFO  Discord.NET - 02:51:06 Gateway     Connecting
2024-07-30 02:51:06,905 [3] INFO  Discord.NET - 02:51:06 Gateway     Resumed previous session
2024-07-30 02:51:06,905 [3] INFO  Discord.NET - 02:51:06 Gateway     Connected
2024-07-30 03:35:16,852 [12] INFO  Discord.NET - 03:35:16 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 03:35:16,853 [12] INFO  Discord.NET - 03:35:16 Gateway     Disconnecting
2024-07-30 03:35:16,853 [12] INFO  Discord.NET - 03:35:16 Gateway     Disconnected
2024-07-30 03:35:17,853 [12] INFO  Discord.NET - 03:35:17 Gateway     Connecting
2024-07-30 03:35:18,302 [12] INFO  Discord.NET - 03:35:18 Gateway     Resumed previous session
2024-07-30 03:35:18,302 [12] INFO  Discord.NET - 03:35:18 Gateway     Connected
2024-07-30 06:16:07,029 [14] INFO  Discord.NET - 06:16:07 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 06:16:07,029 [14] INFO  Discord.NET - 06:16:07 Gateway     Disconnecting
2024-07-30 06:16:07,029 [14] INFO  Discord.NET - 06:16:07 Gateway     Disconnected
2024-07-30 06:16:08,030 [14] INFO  Discord.NET - 06:16:08 Gateway     Connecting
2024-07-30 06:16:08,593 [14] INFO  Discord.NET - 06:16:08 Gateway     Resumed previous session
2024-07-30 06:16:08,593 [14] INFO  Discord.NET - 06:16:08 Gateway     Connected
2024-07-30 09:57:48,783 [9] INFO  Discord.NET - 09:57:48 Audio #1    Unknown OpCode (11)
2024-07-30 09:57:48,783 [9] INFO  Discord.NET - 09:57:48 Audio #1    Unknown OpCode (18)
2024-07-30 09:57:48,783 [9] INFO  Discord.NET - 09:57:48 Audio #1    Unknown OpCode (20)
2024-07-30 10:01:05,670 [15] INFO  Discord.NET - 10:01:05 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 10:01:05,671 [15] INFO  Discord.NET - 10:01:05 Gateway     Disconnecting
2024-07-30 10:01:05,671 [15] INFO  Discord.NET - 10:01:05 Gateway     Disconnected
2024-07-30 10:01:06,671 [15] INFO  Discord.NET - 10:01:06 Gateway     Connecting
2024-07-30 10:01:07,190 [20] INFO  Discord.NET - 10:01:07 Gateway     Resumed previous session
2024-07-30 10:01:07,190 [20] INFO  Discord.NET - 10:01:07 Gateway     Connected
2024-07-30 10:19:57,568 [15] INFO  Discord.NET - 10:19:57 Audio #1    Unknown OpCode (11)
2024-07-30 10:19:57,568 [15] INFO  Discord.NET - 10:19:57 Audio #1    Unknown OpCode (18)
2024-07-30 10:19:57,568 [15] INFO  Discord.NET - 10:19:57 Audio #1    Unknown OpCode (20)
2024-07-30 12:37:50,777 [12] INFO  Discord.NET - 12:37:50 Audio #1    Unknown OpCode (11)
2024-07-30 12:37:50,777 [12] INFO  Discord.NET - 12:37:50 Audio #1    Unknown OpCode (18)
2024-07-30 12:37:50,777 [12] INFO  Discord.NET - 12:37:50 Audio #1    Unknown OpCode (20)
2024-07-30 13:05:05,808 [3] INFO  Discord.NET - 13:05:05 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 13:05:05,809 [3] INFO  Discord.NET - 13:05:05 Gateway     Disconnecting
2024-07-30 13:05:05,809 [3] INFO  Discord.NET - 13:05:05 Gateway     Disconnected
2024-07-30 13:05:06,808 [3] INFO  Discord.NET - 13:05:06 Gateway     Connecting
2024-07-30 13:05:07,256 [3] INFO  Discord.NET - 13:05:07 Gateway     Resumed previous session
2024-07-30 13:05:07,256 [3] INFO  Discord.NET - 13:05:07 Gateway     Connected
2024-07-30 13:34:59,689 [17] INFO  Discord.NET - 13:34:59 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 13:34:59,689 [17] INFO  Discord.NET - 13:34:59 Gateway     Disconnecting
2024-07-30 13:34:59,689 [17] INFO  Discord.NET - 13:34:59 Gateway     Disconnected
2024-07-30 13:35:00,690 [17] INFO  Discord.NET - 13:35:00 Gateway     Connecting
2024-07-30 13:35:01,364 [17] INFO  Discord.NET - 13:35:01 Gateway     Resumed previous session
2024-07-30 13:35:01,365 [17] INFO  Discord.NET - 13:35:01 Gateway     Connected
2024-07-30 13:59:56,661 [18] INFO  Discord.NET - 13:59:56 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 13:59:56,662 [18] INFO  Discord.NET - 13:59:56 Gateway     Disconnecting
2024-07-30 13:59:56,663 [18] INFO  Discord.NET - 13:59:56 Gateway     Disconnected
2024-07-30 13:59:57,664 [12] INFO  Discord.NET - 13:59:57 Gateway     Connecting
2024-07-30 13:59:58,263 [12] INFO  Discord.NET - 13:59:58 Gateway     Resumed previous session
2024-07-30 13:59:58,263 [12] INFO  Discord.NET - 13:59:58 Gateway     Connected
2024-07-30 14:55:13,217 [12] INFO  Discord.NET - 14:55:13 Audio #1    System.Net.WebSockets.WebSocketException (0x80004005): 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.ThrowEOFUnexpected()
   at System.Net.WebSockets.ManagedWebSocket.EnsureBufferContainsAsync(Int32 minimumRequiredBytes, CancellationToken cancellationToken)
   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)
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 14:55:13,218 [12] INFO  Discord.NET - 14:55:13 Audio #1    Disconnecting
2024-07-30 14:55:13,218 [12] INFO  Discord.NET - 14:55:13 Audio #1    Audio connection terminated with unknown reason. Code: 0 - The remote party closed the WebSocket connection without completing the close handshake.:
System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake.
   at System.Net.WebSockets.ManagedWebSocket.ThrowEOFUnexpected()
   at System.Net.WebSockets.ManagedWebSocket.EnsureBufferContainsAsync(Int32 minimumRequiredBytes, CancellationToken cancellationToken)
   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)
2024-07-30 14:55:13,219 [12] INFO  Discord.NET - 14:55:13 Audio #1    Disconnected
2024-07-30 14:55:14,220 [12] INFO  Discord.NET - 14:55:14 Audio #1    Connecting
2024-07-30 14:55:14,755 [6] INFO  Discord.NET - 14:55:14 Audio #1    Unknown OpCode (11)
2024-07-30 14:55:14,755 [6] INFO  Discord.NET - 14:55:14 Audio #1    Unknown OpCode (18)
2024-07-30 14:55:14,755 [6] INFO  Discord.NET - 14:55:14 Audio #1    Unknown OpCode (18)
2024-07-30 14:55:14,755 [6] INFO  Discord.NET - 14:55:14 Audio #1    Unknown OpCode (20)
2024-07-30 14:55:14,755 [6] INFO  Discord.NET - 14:55:14 Audio #1    Unknown OpCode (20)
2024-07-30 14:55:14,755 [6] INFO  Discord.NET - 14:55:14 Audio #1    Connected
2024-07-30 15:13:00,781 [14] INFO  Discord.NET - 15:13:00 Audio #1    Unknown OpCode (11)
2024-07-30 15:13:00,781 [14] INFO  Discord.NET - 15:13:00 Audio #1    Unknown OpCode (18)
2024-07-30 15:13:00,781 [14] INFO  Discord.NET - 15:13:00 Audio #1    Unknown OpCode (20)
2024-07-30 15:14:16,785 [11] INFO  Discord.NET - 15:14:16 Gateway     System.Net.WebSockets.WebSocketException (0x80004005): 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.ThrowEOFUnexpected()
   at System.Net.WebSockets.ManagedWebSocket.EnsureBufferContainsAsync(Int32 minimumRequiredBytes, CancellationToken cancellationToken)
   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)
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 15:14:16,785 [11] INFO  Discord.NET - 15:14:16 Gateway     Disconnecting
2024-07-30 15:14:16,786 [11] INFO  Discord.NET - 15:14:16 Gateway     Disconnected
2024-07-30 15:14:17,786 [11] INFO  Discord.NET - 15:14:17 Gateway     Connecting
2024-07-30 15:14:18,238 [12] INFO  Discord.NET - 15:14:18 Gateway     Resumed previous session
2024-07-30 15:14:18,239 [12] INFO  Discord.NET - 15:14:18 Gateway     Connected
2024-07-30 15:18:19,935 [12] INFO  Discord.NET - 15:18:19 Audio #1    System.Net.WebSockets.WebSocketException (0x80004005): WebSocket connection was closed
 ---> Discord.Net.WebSocketClosedException: The server sent close 1001: ""
   at Discord.Net.WebSockets.DefaultWebSocketClient.RunAsync(CancellationToken cancelToken)
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 15:18:19,935 [12] INFO  Discord.NET - 15:18:19 Audio #1    Disconnecting
2024-07-30 15:18:19,939 [12] INFO  Discord.NET - 15:18:19 Audio #1    Disconnected
2024-07-30 17:33:30,776 [41] INFO  Discord.NET - 17:33:30 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 17:33:30,776 [41] INFO  Discord.NET - 17:33:30 Gateway     Disconnecting
2024-07-30 17:33:30,776 [41] INFO  Discord.NET - 17:33:30 Gateway     Disconnected
2024-07-30 17:33:31,777 [41] INFO  Discord.NET - 17:33:31 Gateway     Connecting
2024-07-30 17:33:32,284 [41] INFO  Discord.NET - 17:33:32 Gateway     Resumed previous session
2024-07-30 17:33:32,284 [41] INFO  Discord.NET - 17:33:32 Gateway     Connected
2024-07-30 18:00:54,801 [11] INFO  Discord.NET - 18:00:54 Audio #2    Connecting
2024-07-30 18:00:55,349 [3] INFO  Discord.NET - 18:00:55 Audio #2    Unknown OpCode (11)
2024-07-30 18:00:55,349 [3] INFO  Discord.NET - 18:00:55 Audio #2    Unknown OpCode (18)
2024-07-30 18:00:55,349 [3] INFO  Discord.NET - 18:00:55 Audio #2    Unknown OpCode (18)
2024-07-30 18:00:55,349 [3] INFO  Discord.NET - 18:00:55 Audio #2    Unknown OpCode (18)
2024-07-30 18:00:55,349 [3] INFO  Discord.NET - 18:00:55 Audio #2    Unknown OpCode (20)
2024-07-30 18:00:55,349 [3] INFO  Discord.NET - 18:00:55 Audio #2    Unknown OpCode (20)
2024-07-30 18:00:55,349 [3] INFO  Discord.NET - 18:00:55 Audio #2    Unknown OpCode (20)
2024-07-30 18:00:55,396 [11] INFO  Discord.NET - 18:00:55 Audio #2    Connected
2024-07-30 18:46:54,454 [14] INFO  Discord.NET - 18:46:54 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 18:46:54,454 [14] INFO  Discord.NET - 18:46:54 Gateway     Disconnecting
2024-07-30 18:46:54,454 [14] INFO  Discord.NET - 18:46:54 Gateway     Disconnected
2024-07-30 18:46:55,455 [14] INFO  Discord.NET - 18:46:55 Gateway     Connecting
2024-07-30 18:46:56,072 [14] INFO  Discord.NET - 18:46:56 Gateway     Resumed previous session
2024-07-30 18:46:56,072 [14] INFO  Discord.NET - 18:46:56 Gateway     Connected
2024-07-30 20:22:37,595 [25] INFO  Discord.NET - 20:22:37 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 20:22:37,595 [25] INFO  Discord.NET - 20:22:37 Gateway     Disconnecting
2024-07-30 20:22:37,595 [25] INFO  Discord.NET - 20:22:37 Gateway     Disconnected
2024-07-30 20:22:38,594 [25] INFO  Discord.NET - 20:22:38 Gateway     Connecting
2024-07-30 20:22:39,280 [30] INFO  Discord.NET - 20:22:39 Gateway     Connected
2024-07-30 20:22:39,280 [25] INFO  Discord.NET - 20:22:39 Gateway     Resumed previous session
2024-07-30 22:52:39,056 [12] INFO  Discord.NET - 22:52:39 Gateway     Discord.WebSocket.GatewayReconnectException: Server requested a reconnect
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
2024-07-30 22:52:39,056 [12] INFO  Discord.NET - 22:52:39 Gateway     Disconnecting
2024-07-30 22:52:39,056 [12] INFO  Discord.NET - 22:52:39 Gateway     Disconnected
2024-07-30 22:52:40,057 [12] INFO  Discord.NET - 22:52:40 Gateway     Connecting
2024-07-30 22:52:40,868 [12] INFO  Discord.NET - 22:52:40 Gateway     Resumed previous session
2024-07-30 22:52:40,868 [12] INFO  Discord.NET - 22:52:40 Gateway     Connected

Sample

No response

Packages

image

Environment

Linux and windows, both the same issue.

@Dragonox77 Dragonox77 added the bug label Aug 1, 2024
@mwpowellhtx
Copy link

I am struggling with this one as well, and after having put in some strategic logging, reaching the conclusion, StartAsync may be leaving its context prior to an established connection. The logs indicating Connecting ... Not Connected. Is there a way in which we may safely and efficiently wait for a proper Connected state before proceeding?

Thought being, I do not necessarily wish to sustain a persistent connection, although perhaps that is how it should be done, I do not know. Rather, might like to connect, atomically, transactionally, do a thing, and disconnect. But again, perhaps that is not a great way of approaching it either.

Let's say connection is sustained throughout a given session. Then should be able to do all the usual sorts of inquiries, on guilds, channels text, messages, etc.

@mwpowellhtx
Copy link

I am at least getting as far as seeing theguild which my prototype bot is tentatively a member, so that's a good step forward 👍 . Next is to somehow persuade a response, or downloads, cache, what have you, for things like text channels, messages, etc. The key I have found getting that far is to park a task opposite an async Connected EH. Run the action and return from the EH quickly, at least so far.

// There's more, but this is key
const ulong gid = default; // Or your guild id
var guilds = client.Guilds.ToArray(); // Does positively return the guild memberships
var guild = client.GetGuild(gid); // Does return the guild, although the internals are not filled, i.e. Name and such

Although anything behind the gid is null, most probably because it has not been downloaded or cached, "yet" i.e. on Connected, or pending a further such object method.

Anything more advanced TL;DR; coming up to speed on things like the modules, services, things of this nature. 🍼 baby steps right 🍖 .

@mwpowellhtx
Copy link

Okay so the Connected event gets you so far. You do have to respond toward the Ready event for things to be more or less kosher and synchronized. After that, successful at finding the guild name, as well as engaging with the channels. Even sent a test message successfully with the desired secondary effect. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants