Skip to content
This repository has been archived by the owner on Jul 17, 2023. It is now read-only.

SSL Error #32

Closed
tielur opened this issue May 31, 2017 · 6 comments
Closed

SSL Error #32

tielur opened this issue May 31, 2017 · 6 comments

Comments

@tielur
Copy link
Contributor

tielur commented May 31, 2017

Is anyone else getting these errors? They seem to continuously happen, I haven't timed exactly how far a part they happen though. I've replaced what I thought was sensitive information with REMOVED. It looks like it's something with the websocket library maybe?

17:23:52.556 [error] ** State machine #PID<0.1098.0> terminating 
** Last message in was {:ssl_closed,
 {:sslsocket, {:gen_tcp, #Port<0.11004>, :tls_connection, :undefined},
  #PID<0.1100.0>}}
** When State == :connected
**      Data  == {:context,
 {:websocket_req, :wss, 'gateway.discord.gg', 443, '/?v=4&encoding=etf',
  :infinity, :undefined, 1,
  {:sslsocket, {:gen_tcp, #Port<0.11004>, :tls_connection, :undefined},
   #PID<0.1100.0>},
  {:transport, :ssl, :ssl, :ssl_closed, :ssl_error,
   [mode: :binary, active: true, verify: :verify_none, packet: 0]},
  "REMOVED", :undefined, 1, 2, :undefined, :undefined},
 {:transport, :ssl, :ssl, :ssl_closed, :ssl_error,
  [mode: :binary, active: true, verify: :verify_none, packet: 0]}, [],
 {:wss, 'gateway.discord.gg', 443, '/?v=4&encoding=etf'},
 {DiscordEx.Client,
  %{agent_seq_num: #PID<0.1099.0>, client_id: REMOVED,
    client_pid: #PID<0.1098.0>,
    guilds: [%{guild_id: REMOVED, voice_states: []}],
    handler: Albionbot.Bot, rest_client: #PID<0.1097.0>,
    session_id: "b664e142fa6cd8c6ace0daa4d1a0c91b",
    token: "Bot REMOVED"}},
 "", false, 0}
** Reason for termination = 
** {{:case_clause, nil},
 [{:websocket_client, :disconnect, 2,
   [file: '/Users/tielur/sites/albionbot/deps/websocket_client/src/websocket_client.erl',
    line: 260]}, {:gen_fsm, :handle_msg, 7, [file: 'gen_fsm.erl', line: 451]},
  {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 247]}]}
@jussih
Copy link
Contributor

jussih commented Jul 23, 2017

I'm getting the same error, the websocket is often closed after only 2 minutes of uptime. The stacktrace you are mentioning is actually because the ondisconnect handler in discord_ex does not have a return value and the websocket behaviour is expecting one. If you change the ondisconnect thusly:

  def ondisconnect({:remote, :closed}, _state) do
    # Stub for beter actions later
    {:close, {:remote, :closed}, _state}
  end

You get the intended reaction and the websocket library wraps itself up neatly and terminates. This does not lead anywhere though, the end result is still the same, the connection is dead :)

Discord documentation states that when the server side disconnects the socket it returns an error code telling why it did so (https://discordapp.com/developers/docs/topics/gateway#disconnections) but this information is lost because the websocket library does not handle it: sanmiguel/websocket_client#48

To get to the actual reason for disconnections, we'd need the information in the close code when/if discord is deciding to cut the socket.

@jussih
Copy link
Contributor

jussih commented Jul 23, 2017

I did a quick hack to update discord_ex to use discord's gateway protocol version 6, and in a couple of trials there were no more disconnects. Protocol version 4 which is currently used is deprecated and going to be removed on October 16th 2017, so the upgrade is needed anyway.

@tielur
Copy link
Contributor Author

tielur commented Jul 24, 2017

@jussih Do you have a fork with these changes?

@jussih
Copy link
Contributor

jussih commented Jul 24, 2017

@tielur https://github.com/jussih/discord_ex/tree/apiv6

The branch implements the bare minimum required to use the v6 protocol. It would be possible to detect a stale websocket due to the heartbeat ACK messages and reconnect and resume automatically, but I haven't implemented that.

@jussih
Copy link
Contributor

jussih commented Nov 12, 2017

This should be fixed now that #43 is merged.

ontofractal added a commit to metachaos-systems/ex_golos that referenced this issue Dec 21, 2017
@tielur
Copy link
Contributor Author

tielur commented Feb 22, 2018

I haven't seen this error in awhile, I'll reopen if it becomes an issue.

@tielur tielur closed this as completed Feb 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants