bananaphone

bananaphone

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?

Showing Posts 1 to 3

al2o3cr

al2o3cr

How is the code you’ve posted connected to the error message? It’s tricky to say for sure without a stack trace, but I don’t see any with statements inside the implementation of WebSockex.start_link so it doesn’t seem directly related.

The error is also concerning: the thing it’s trying to match looks like an exception payload ({:function_clause, {WebSockex, :call, [%WebSockex.Conn{) caused by something trying to call WebSockex.call(conn, ...) which isn’t a function defined in WebSockex.

bananaphone

bananaphone OP

Yeah from what I can tell it looks like WebSockex is trying to do a callback on the module its start_link is called from, although when I look through the code on GitHub I don’t see it doing that, I am new to Elixir so I’m not so great at reading it yet though. (EDIT: it is not doing this.)

Mainly I was hoping someone on here could tell me if, categorically, calling start_link on a process thingy in a handle_info is not allowed or this is probably some kind of WebSockex problem. Now I am leaning toward WebSockex problem. The docs for WebSockex say it is implemented as a “special process.”

Basically I am trying to write wrapper code that asynchronously starts websocket connections and can just retry on a delay if the remote connection isn’t available yet, as a way to make my application more resilient, as it should continue to run even if it can’t establish a websocket connection yet. This thread and comment was the impetus: How to make a Supervisor **never** die? - #23 by brucepomeroy

WebSockex doesn’t seem amenable to this since I can’t start it outside start_link so I might have to just get better at Elixir and fork the project.

bananaphone

bananaphone OP

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews