bananaphone

bananaphone

WebSockex start_link outside GenServer start_link fails in keepalive pattern

I am trying to wrap the WebSockex library so that it is initialized asynchronously, and if the websocket source is unavailable or becomes unavailable, the application stays alive and just retries in 60 seconds. To this end I have created a GenServer, and in its init callback I am doing Process.send_after(self(), :websocket_connect, 0) and my handle_info looks like this:

try do
      with {:ok, pid} <-
             WebSockex.start_link(
               url,
               MyHandler,
               {},
               async: false,
               handle_initial_conn_failure: true
             ) do
        Logger.info("Success starting websocket.")

...

rescue
      e ->
        Logger.error("Runtime error establishing websocket connection")
        Process.send_after(self(), :websocket_connect, 60_000)
        {:noreply, state}
    end

If I call WebSockex.start_link inside a GenServer start_link the command works. If I put it in my handle_info callback it fails with:

14:21:38.470 [error] ** (WithClauseError) no with clause matching: {:function_clause, {WebSockex, :call, [%WebSockex.Conn{conn_mod: :gen_tcp, host: (bunch of websocket connection info)

What am I doing wrong? Is it not possible to call this function outside of another start_link? Or is this an issue with WebSockex?

Marked As Solved

bananaphone

bananaphone

Completely by accident I found the problem, I really was using the library wrong. I completely restructured the code and then Dialyzer told me I was doing something wrong (don’t know why it didn’t complain before or why the original error message was so misleading.) The mistake is not relevant to the question so I won’t clutter the thread with it.

Where Next?

Popular in Questions Top

Tee
can someone please explain to me how Enum.reduce works with maps
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement