benonymus
Hey there,
I created a small genserver and it works great but I want to add a timeout to a call, and to test it in the handle_call/3 I am doing Process.sleep/1 with a longer time then the timeout, but instead of getting a :timeout message to catch in handle_info/2 I am just getting an error that says:
** (exit) exited in: GenServer.call(Checksum.Checksum, :calculate, 50)
** (EXIT) time out
here is the call:
def calculate_checksum() do
GenServer.call(__MODULE__, :calculate, 50)
end
here is the handle:
@impl GenServer
def handle_call(:calculate, _, state) do
Process.sleep(60)
result = 0
{:reply, {:ok, result}, state}
end
this is where I would expect to catch the timeout:
@impl GenServer
def handle_info(:timeout, state) do
{:reply, {:error, :timeout}, state}
end
What am I missing? ![]()
Thanks
Trending in Questions
Hey guys,
I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly
Do you guys have any suggestions what is the best prac...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
Anyone here using Honeybadger?
My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of
Bandit.HTTPError...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #ai
- #elixirconf-us
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
kokolegorille
Where is your timeout defined?
benonymus
The 50 I believe
kokolegorille
No, it’s should not be like that…
It’s when You return from any call that You specify timeout.
like {:reply, state, state, timeout}
benonymus
But what about this?
kokolegorille
It is not the same timeout. One is the client timeout, one is the server timeout.
Please note server handlers should also return timeout, even init.
kokolegorille
Here is an example…
stop and clean is a custom function…
benonymus
And how can I make this timeout?
What I actually want to use is to show a different response if the timeout happens.
Now I added the timeout to where you said, and I am getting the :timeout message.
But where I am making the call to the genserver I am still getting the result.
As you saw from my handle_call for :calculate I am returning {:ok, result}, but I am also seeing the :timeout message being handled.
What would be ideal if there is a timeout instead of getting {:ok, result} I could get something like {:error, :timeout} but If I do reply with this error and state in the handle_info then it is a bad return value.
benonymus
I think I was on the right path based on this: gen_server — OTP 29.0.2 (stdlib 8.0.1)
And I think I have this problem:
https://groups.google.com/g/elixir-lang-talk/c/7tS9tX7fLpg
I tried to put the genserver call in try do but no success yet
amnu3387
When you do a
callwith a timeout this is the timeout the caller process will wait before it throws an exception. You need torescuethis exception at the call site.The
timeoutin a gen_server (the one you can set in the callback of any handle) is an internal timeout that sets an amount of time the gen_server can be without receiving any message, which upon it elapsing triggers an internal message of:timeoutthat you can handle. This timeout is disabled whenever a message arrives in the gen_servers mailbox and needs to be set again if you wish it to trigger again.benonymus
Hey, thanks for the response!
I am trying this:
but no success