Open centuriononon opened 7 months ago
Thanks for pointing me to the right direction as this has been troubling me for some time.
A workaround is to send a ping frame every 30 seconds.
def handle_pong(_, %{ connected: false }=state), do: {:ok, state}
def handle_pong(_, %{ connected: true }=state), do: {:ok, %{ state| pong_received: true }}
def handle_connect(_conn, _state) do
Process.send_after(self(), :ping_timeout, @ping_timeout)
{ :ok, %__MODULE__{ pong_received: true, connected: true } }
end
def handle_info(:ping_timeout, state) do
case state do
%{ pong_received: true } ->
Process.send_after(self(), :ping_timeout, @ping_timeout)
{:reply, {:ping, ""}, %{ state| pong_received: false }}
%{ pong_received: false } ->
{:close, state}
end
end
Conditions
OS: Arch Linux x86_64 Kernel: 6.8.1-arch1-1 Erlang: 26.0 Elixir: 1.16.0-otp-26
Dependencies: Jason: 0.4.3 WebSockex: 1.4.1
Description
The problem is that when disconnecting the ethernet device, the WebSockex server does not always reconnect.
It reconnects only if the connection is lost for no more than 5 seconds. If more time has passed, it does not reconnect anymore and the debugger does not register anything useful.
Flow I expected
eno1
connectedFlow 1: Fast reconnection, as I expected
Flow 2: Long reconnection, as I did not expected
Initial setup 15:01:47 (eno1 connected, socket receives events):
Disconnection 15:02:10 (eno1 disconnected, socket does not receive events):
Reconnection 15:07:12 (eno1 connected, socket still does not receive events)
BasicSocket:
Main question
Why WebSockex reconnects for a short disconnection periods, and does not reconnect for long periods in this case?
Side question
Why is the debugger so laggy in iex sessions?
Are there other options to debug my case? How can I get additional information about what happens under the "hood"?