Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Connection Websocket upgrade failed #524

Closed
tidusIO opened this issue Oct 18, 2023 · 4 comments
Closed

Connection Websocket upgrade failed #524

tidusIO opened this issue Oct 18, 2023 · 4 comments

Comments

@tidusIO
Copy link

tidusIO commented Oct 18, 2023

Since switching to the latest master I get following repeating error when starting my application. This happens in Google Cloud and my local macOS system as well.

[info] WAITING 128 BEFORE NEXT SHARD CONNECT
[debug] Upgrading connection to websocket
[debug] Shard connection up, waiting for consumers to boot
[error] ** State machine <0.1213.0> terminating
** Last event = {info,{gun_upgrade,<0.1214.0>,
                                   #Ref<0.2030176606.2015625217.39321>,
                                   [<<"websocket">>],
                                   [{<<"date">>,
                                     <<"Wed, 18 Oct 2023 17:26:32 GMT">>},
                                    {<<"connection">>,<<"upgrade">>},
                                    {<<"sec-websocket-accept">>,
                                     <<"XTX4ZupV6bXSO3Txkhavuwd22D4=">>},
                                    {<<"upgrade">>,<<"websocket">>},
                                    {<<"cf-cache-status">>,<<"DYNAMIC">>},
                                    {<<"report-to">>,
                                     <<"{\"endpoints\":[{\"url\":\"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=RQzrHe90NXM3fNbUxzSRVnVs9hWpdOGipWPR%2FBbWQL%2BA0v267FBgfcViDC85WxoAzwtevd6xku7G2UhJJYhbqBLKsfvpW%2FI53iGlAy8Ujy1LUnaEV0YPiRmiJmv9nk4IpK8n4w%3D%3D\"}],\"group\":\"cf-nel\",\"max_age\":604800}">>},
                                    {<<"nel">>,
                                     <<"{\"success_fraction\":0,\"report_to\":\"cf-nel\",\"max_age\":604800}">>},
                                    {<<"strict-transport-security">>,
                                     <<"max-age=31536000; includeSubDomains; preload">>},
                                    {<<"x-content-type-options">>,
                                     <<"nosniff">>},
                                    {<<"server">>,<<"cloudflare">>},
                                    {<<"cf-ray">>,
                                     <<"81827ca38dca9325-ICN">>}]}}
** When server state  = {connecting_ws,
                            #{stream => #Ref<0.2030176606.2015625217.39321>,
                              seq => nil,
                              '__struct__' => 'Elixir.Nostrum.Struct.WSState',
                              session => nil,conn => <0.1214.0>,
                              gateway => <<"gateway.discord.gg">>,
                              last_heartbeat_ack => nil,
                              last_heartbeat_send => nil,
                              heartbeat_interval => nil,shard_num => 0,
                              heartbeat_ack => nil,zlib_ctx => nil,
                              resume_gateway => nil,conn_pid => <0.1213.0>,
                              total_shards => 1}}
** Reason for termination = error:{badmatch,timeout}
** Callback modules = ['Elixir.Nostrum.Shard.Session']
** Callback mode = [state_functions,state_enter]
** Stacktrace =
**  [{'Elixir.Nostrum.Shard.Session',connected,3,
                                     [{file,"lib/nostrum/shard/session.ex"},
                                      {line,239}]},
     {gen_statem,loop_state_callback,11,[{file,"gen_statem.erl"},{line,1377}]},
     {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,241}]}]
** Time-outs: {1,[{state_timeout,upgrade_timeout}]}```
@tidusIO
Copy link
Author

tidusIO commented Oct 19, 2023

Alright, I found my issue. I didn't have any consumers, because I just use HTTP Requests and don't need to listen to any events. Maybe it would be helpful if there is any check before if there are any consumers or not before running in "timeout".

@tidusIO tidusIO closed this as completed Oct 19, 2023
jchristgit added a commit that referenced this issue Oct 19, 2023
Instead of relying on the user to interpret the existing debug logs and
badmatch error, send an explicit error message when no consumer could be
found that we can use in the shard connection. See #524.
jchristgit added a commit that referenced this issue Oct 19, 2023
Instead of relying on the user to interpret the existing debug logs and
badmatch error, send an explicit error message when no consumer could be
found that we can use in the shard connection. See #524.
@kiddoshainingu
Copy link

Alright, I found my issue. I didn't have any consumers, because I just use HTTP Requests and don't need to listen to any events. Maybe it would be helpful if there is any check before if there are any consumers or not before running in "timeout".

How did you manage to bypass the error?
I am in a similar case as you and for some reason, I am now running into that error and don't know how to solve it 😅

@jb3
Copy link
Collaborator

jb3 commented May 2, 2024

@kiddoshainingu on Nostrum latest, the error should change now into something like "No consumers were running nor did any start up in time...".

I'd advise you to just spin up a dummy consumer for this purpose, just something like ```elixir
defmodule MyBot.DummyConsumer do
use Nostrum.Consumer
end


Then as long as that gets started by a supervisor when Nostrum starts, things should be fine.

@kiddoshainingu
Copy link

@jb3 Thank you very much ! Problem solved. 🙏🏾

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

No branches or pull requests

3 participants