shardlab / discordrb

Discord API for Ruby
MIT License
538 stars 99 forks source link

"An existing connection was forcibly closed by the remote host" results in reconnect attempts multiple times per second #268

Open rpherbig opened 3 months ago

rpherbig commented 3 months ago

Summary

I've got a discord bot that listens for commands in a channel. For long periods of time it's effectively idle. Most of the time this is fine, after what I presume is an idle timeout the bot is disconnected and reconnects just fine:

[ERROR : websocket @ 2024-08-09 11:14:38.577] The websocket connection has closed: (no information)
[INFO : websocket @ 2024-08-09 11:14:38.578] Instant reconnection flag was set - reconnecting right away
[INFO : websocket @ 2024-08-09 11:14:39.227] Resumed

However, sometimes I get behavior like this:

[INFO : websocket @ 2024-08-09 11:14:38.578] Instant reconnection flag was set - reconnecting right away
[INFO : websocket @ 2024-08-09 11:14:39.227] Resumed
[ERROR : websocket @ 2024-08-09 13:32:56.592] The websocket connection has closed: (no information)
[INFO : websocket @ 2024-08-09 13:32:56.592] Instant reconnection flag was set - reconnecting right away
[INFO : websocket @ 2024-08-09 13:32:57.299] Resumed
[ERROR : websocket @ 2024-08-09 14:04:09.399] An error occurred in the main websocket loop!
[ERROR : websocket @ 2024-08-09 14:04:09.399] Exception: #<Errno::ECONNRESET: An existing connection was forcibly closed by the remote host.>
[ERROR : websocket @ 2024-08-09 14:04:09.400] C:/Ruby32-x64/lib/ruby/3.2.0/openssl/buffering.rb:157:in `sysread'
[ERROR : websocket @ 2024-08-09 14:04:09.401] C:/Ruby32-x64/lib/ruby/3.2.0/openssl/buffering.rb:157:in `readpartial'
[ERROR : websocket @ 2024-08-09 14:04:09.402] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:602:in `websocket_loop'
[ERROR : websocket @ 2024-08-09 14:04:09.403] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:579:in `connect'
[ERROR : websocket @ 2024-08-09 14:04:09.404] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:473:in `block in connect_loop'
[ERROR : websocket @ 2024-08-09 14:04:09.408] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:472:in `loop'
[ERROR : websocket @ 2024-08-09 14:04:09.409] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:472:in `connect_loop'
[ERROR : websocket @ 2024-08-09 14:04:09.410] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:168:in `block in run_async'
[ERROR : websocket @ 2024-08-09 14:04:09.412] An error occurred in the main websocket loop!
[ERROR : websocket @ 2024-08-09 14:04:09.413] Exception: #<Errno::ECONNRESET: An existing connection was forcibly closed by the remote host.>
[ERROR : websocket @ 2024-08-09 14:04:09.414] C:/Ruby32-x64/lib/ruby/3.2.0/openssl/buffering.rb:157:in `sysread'
[ERROR : websocket @ 2024-08-09 14:04:09.416] C:/Ruby32-x64/lib/ruby/3.2.0/openssl/buffering.rb:157:in `readpartial'
[ERROR : websocket @ 2024-08-09 14:04:09.417] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:602:in `websocket_loop'
[ERROR : websocket @ 2024-08-09 14:04:09.419] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:579:in `connect'
[ERROR : websocket @ 2024-08-09 14:04:09.420] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:473:in `block in connect_loop'
[ERROR : websocket @ 2024-08-09 14:04:09.421] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:472:in `loop'
[ERROR : websocket @ 2024-08-09 14:04:09.422] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:472:in `connect_loop'
[ERROR : websocket @ 2024-08-09 14:04:09.424] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:168:in `block in run_async'
[ERROR : websocket @ 2024-08-09 14:04:09.426] An error occurred in the main websocket loop!
[ERROR : websocket @ 2024-08-09 14:04:09.426] Exception: #<Errno::ECONNRESET: An existing connection was forcibly closed by the remote host.>
[ERROR : websocket @ 2024-08-09 14:04:09.427] C:/Ruby32-x64/lib/ruby/3.2.0/openssl/buffering.rb:157:in `sysread'
[ERROR : websocket @ 2024-08-09 14:04:09.427] C:/Ruby32-x64/lib/ruby/3.2.0/openssl/buffering.rb:157:in `readpartial'
[ERROR : websocket @ 2024-08-09 14:04:09.428] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:602:in `websocket_loop'
[ERROR : websocket @ 2024-08-09 14:04:09.429] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:579:in `connect'
[ERROR : websocket @ 2024-08-09 14:04:09.432] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:473:in `block in connect_loop'
[ERROR : websocket @ 2024-08-09 14:04:09.434] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:472:in `loop'
[ERROR : websocket @ 2024-08-09 14:04:09.435] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:472:in `connect_loop'
[ERROR : websocket @ 2024-08-09 14:04:09.436] C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/discordrb-3.5.0/lib/discordrb/gateway.rb:168:in `block in run_async'

and the exception repeats every few milliseconds


Environment

Ruby version:

PS C:\...> ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt]

Discordrb version:

PS C:\...> gem list discordrb

*** LOCAL GEMS ***

discordrb (3.5.0)
discordrb-webhooks (3.5.0)