kaa.python
My Genserver terminates after a little while, after sending a few http requests. I can’t understand the reason:
[error] GenServer MyGenServer terminating
** (stop) exited in: Task.await(%Task{owner: #PID<0.420.0>, pid: #PID<0.1054.0>, ref: #Reference<....>}, 5000)
** (EXIT) time out
(elixir) lib/task.ex:416: Task.await/2
(elixir) lib/enum.ex:966: Enum.flat_map_list/2
(my_app123) lib/my_genserver.ex:260: MyApp.MyGenServer.do_work/1
(my_app123) lib/my_genserver.ex:180: MyApp.MyGenServer.handle_info/2
(stdlib) gen_server.erl:601: :gen_server.try_dispatch/4
(stdlib) gen_server.erl:683: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Last message: :tick
State: [%{var1: "fdsafdsfd", var2: "43243242"}]
A chunk of the code:
# it's called from handle_info
def do_work(some_data) do
Enum.map(some_data, fn(x) ->
Task.async(fn ->
case HTTPoison.post(.....) do
# ...........
Is “Task.async” causing the timeout? But why? Yes, it can take more than 5 seconds to complete, but why does it cause an exception which then terminates GenServer? How to fix it?
About await:
If the timeout is exceeded, await will exit; however, the task will continue to run. When the calling process exits, its exit signal will terminate the task if it is not trapping exits.
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
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
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)
NobbZ
Task.await/1callsexit/1on timeout, so it will end your current process. If you do not wan’t that behaviour you will have to implement the receiving of the result and receiving of:DOWNmessages on your own.benperiton
I’m still getting to grips with Tasks myself, but I think it’s because the Task is linked to the calling process, so if it throws an error and exits, then the calling process will also die. See Task — Elixir v1.20.2
You could use
Task.start_link/1if you don’t need the response, I’ve been using a Task.Supervisor for mine, so that if a Task dies, it doesn’t bring the genserver down.Add a supervisor:
Then can use it like:
Because I wnted to know if it was a timeout, I use
yieldkaa.python
How and where?
Or maybe I could
kaa.python
but I already have this in:
NobbZ
I’m not sure what you mean by using
try/catchinTask.await/1, since you can’t alterTask.await/1. You can look at its implementation though to see how the different kind of messages look like, then you will know how to math them inhandle_info/2. I’m not quite sure what will be the best way to time out aTaskthen, though…If you mean you wan’t to wrap
Task.await/1withtry/catch, this won’t work either.exit/1does end the process. It does end the process. There is notry, nothingraised orthrown, onlyexit.benperiton
Again, I’m not sure this is the best way as I’m still learning myself, but something like:
Add
supervisor(Task.Supervisor, [[name: MyWebApp.TaskSupervisor]])to the appThen inside MyWebApp.MyGenServer you could do:
The reason I switched to using
Task.yieldwas because I wanted to be able to trap timeouts (it sends back nil) so that I could do something with it.kaa.python
I mean this:
kaa.python
How about Task.yield instead Task.async, will it work?
kaa.python
How will I know that it’s the “exit” or :DOWN sent exactly from that Task.await?
NobbZ
That of course would work, but you have to do it in every
Taskyou spawn, also this will not do anything about a timeout inTask.await/1!What do you wan’t to return in the case that there was no answer before having the
yieldtiming out?It won’t exit on
raisethough, but give you an:error-tuple which you could return straight.By using a map to map your
Taskto your callers. roughly like this:How to pull of the correct value from the state is left as an exercise for the reader
Also I have to admit that the code is untested since I currently have no access to a properly set up elixir environment.