-
Notifications
You must be signed in to change notification settings - Fork 110
Open
Description
Hello,
If a Websockex client crashes in an unsupervised instance, the log catches the exit error, for instance using a simplified version of the echo_client.exs example:
defmodule EchoClient do
use WebSockex
require Logger
def start_link(opts \\ []) do
WebSockex.start_link("wss://ws.postman-echo.com/raw", __MODULE__, :fake_state, opts)
end
@spec echo(pid, String.t) :: :ok
def echo(client, message) do
Logger.info("Sending message: #{message}")
WebSockex.send_frame(client, {:text, message})
end
def echo_supervised(message) do
Logger.info("Sending message: #{message}")
WebSockex.send_frame(__MODULE__, {:text, message})
end
def handle_connect(_conn, state) do
Logger.info("Connected!")
{:ok, state}
end
def handle_frame({:text, msg}, :fake_state) do
Logger.info("Received Message: #{msg}")
if :rand.uniform() > 0.5 do
Logger.info("Raising random error to crash the client")
raise ArgumentError
end
{:ok, :fake_state}
end
end
{:ok, pid} = EchoClient.start_link()
EchoClient.echo(pid, "Yo Homies!")
EchoClient.echo(pid, "This and That!")
EchoClient.echo(pid, "Can you please reply yourself?")Returns something like
[info] Raising random error to crash the client
** (EXIT from #PID<0.95.0>) {%ArgumentError{message: "argument error"}, []}
Now using a supervised version, the Client when crashing just silently restarts:
For instance using the Websockex Application, just for this example:
defmodule WebSockex.Application do
use Application
"""
def start(_type, _args) do
unless URI.default_port("ws"), do: URI.default_port("ws", 80)
unless URI.default_port("wss"), do: URI.default_port("wss", 443)
Supervisor.start_link(
[
{EchoClient, name: EchoClient}
],
strategy: :one_for_one,
name: WebSockex.Supervisor
)
end
endThen we can run
iex -S mix
iex(0)> EchoClient.echo_supervised("hi")
When the error raises, we just get
[info] Raising random error to crash the client
[info] Connected!
Shouldn't it also catch the crash log like in the unsupervised method? I tried using the debug: [:trace] option, but this logs everything and often is not convenient with logs overflowing. Perhaps I'm missing an option?
Thanks!
Metadata
Metadata
Assignees
Labels
No labels