discord-net / Discord.Net

An unofficial .Net wrapper for the Discord API (https://discord.com/)
https://discordnet.dev
MIT License
3.32k stars 737 forks source link

Timeouts & websocket closed #1336

Closed Lymdun closed 5 years ago

Lymdun commented 5 years ago

Hello,

It seems that since 2.1.1, I can't use Discord.Net in production anymore ; Shards are getting lot of timeouts recently, with this stacktrace ;

System.TimeoutException : The operation has timed out.
   at Discord.Net.Queue.RequestBucket.EnterAsync(Int32 id, RestRequest request)
   at Discord.Net.Queue.RequestBucket.SendAsync(RestRequest request)
   at Discord.Net.Queue.RequestQueue.SendAsync(RestRequest request)
   ...

Also, I can get these errors, and no reconnect after that : WebSocket connection was closed ---> The server sent close 1000 : ""

It's hard to repro since it seems to happen only after several hours of running bot. Also, it doesn't seems to happen to every shards.

Environment: Linux Debian Discord .Net version : 2.1.1 WebSockets : Default

By the way, since it's the first time I have the opportunity to say it ; Thanks a lot for your awesome work!

Lymdun commented 5 years ago

Seems that increasing the value of DefaultRequestTimeout did the job to get rid of the timeouts, but not of the disconnections. Here are more stacktrace of the errors ;

7/1/19 12:49:22 AM  [Warning] Shard #1:  System.Exception: WebSocket connection was closed ---> Discord.Net.WebSocketClosedException: The server sent close 1000: ""
   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()

After the shard reconnected, others were disconnected ;

7/1/19 12:52:46 AM  [Info] Shard #3: Disconnecting 
7/1/19 12:52:46 AM  [Info] Shard #1: Disconnecting 
7/1/19 12:52:46 AM  [Info] Shard #2: Disconnecting 
7/1/19 12:52:46 AM  [Info] Shard #5: Disconnecting 
7/1/19 12:52:46 AM  [Warning] Shard #1:  System.Exception: Server missed last heartbeat
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
7/1/19 12:52:46 AM  [Warning] Shard #3:  System.Exception: Server missed last heartbeat
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
7/1/19 12:52:46 AM  [Warning] Shard #5:  System.Exception: Server missed last heartbeat
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()
7/1/19 12:52:46 AM  [Warning] Shard #2:  System.Exception: Server missed last heartbeat
   at Discord.ConnectionManager.<>c__DisplayClass29_0.<<StartAsync>b__0>d.MoveNext()

Note that I'm using Program.cs & CommandHandlingService from your sharded_client sample. I'm using a VPS with 8Gb of RAM & 8 CPU cores

Lymdun commented 5 years ago

After heavy tests, it seemed that the issue can be reproduced when spamming a command, even a simple one doing a await ReplyAsync()

Still34 commented 5 years ago

Are you running the comamnds in RunMode.Sync by any chance? By default, this is the expected behaviour since the command runs sequentially with the gateway thread.

Lymdun commented 5 years ago

Are you running the comamnds in RunMode.Sync by any chance? By default, this is the expected behaviour since the command runs sequentially with the gateway thread.

No, even commands with RunMode.Async are causing it

Still34 commented 5 years ago

Also, note that this may be a duplicate of #1220, #1207, #960, #856.

Lymdun commented 5 years ago

For reference, issue solved with a simple cooldown system

RheaAyase commented 4 years ago

simple cooldown system

Isn't that the purpose of an API wrapper library?

RheaAyase commented 4 years ago

For all intents and purposes this ticket is still valid and not a duplicate of #960 that's... not exactly the same problem. #1220 is

Abubakarstu commented 1 year ago

14:17:38 Discord Discord.Net v3.9.0 (API v10) 14:17:38 Gateway Connecting 14:17:42 Gateway System.Exception: WebSocket connection was closed ---> Discord.Net.WebSocketClosedException: The server sent close 4014: "Disallowed intent(s)." at Discord.Net.WebSockets.DefaultWebSocketClient.RunAsync(CancellationToken cancelToken) --- End of inner exception stack trace --- at Discord.ConnectionManager.WaitAsync() at Discord.WebSocket.DiscordSocketClient.OnConnectingAsync() at Discord.ConnectionManager.ConnectAsync(CancellationTokenSource reconnectCancelToken) at Discord.ConnectionManager.<>c__DisplayClass29_0.<b__0>d.MoveNext() 14:17:42 Gateway Disconnecting 14:17:42 Gateway Disconnected