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
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
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
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
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
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
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
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
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
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










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