gen_server stands for "generic server", a module behaviour in Erlang.
Questions tagged [gen-server]
315 questions
4
votes
1 answer
Erlang gen_server eaddrnotavail after 16358 gen_tcp:connect calls
I'm writing a server in Erlang and want to open a large number of connections. The problem is that I receive {error, eaddrnotavail} after 16358 gen_tcp:connect/3 calls. As you can see below, the server is pretty simple.
I modified my MacOS Yosemite…

Ștefan Stan
- 223
- 1
- 7
4
votes
2 answers
Erlang: how to get result from init() in gen_server
My init() function creates UDP Socket and Returns Socket value as a State.
start() ->
{ok, ServerPid} = gen_server:start_link(?MODULE, [], []).
%%% gen_server API
init([]) ->
{ok, Socket} = gen_udp:open(8888, [list,…

Atlas
- 179
- 1
- 2
- 9
4
votes
2 answers
Why is erlang io:format output being lost and what do I need to do to restore it?
I'm writing a gen_server, which we'll just call gen_server_db, with nothing too terribly special about it. There is a possibility that a library it uses (emysql) will experience a connection failure while trying to find a database server (in…

Sniggerfardimungus
- 11,583
- 10
- 52
- 97
3
votes
1 answer
Erlang supervisor. Restarting process, if it fails several times, give up and send message
I have several gen_server workers periodically requesting some information from hardware sensors. Sensors may temporary fail, it is normal. If sensor fails worker terminates with an exception.
All workers are spawned form supervisor with…

galadog
- 960
- 2
- 10
- 20
3
votes
1 answer
Erlang + Apple Push notification [Issue with invalid token]
I'm currently trying to create a push notification module for Erlang.
When the token is valid, everything works great...
The issue is when an old device token (which is invalid by now) is rejected.
I understand that invalid token will be rejected by…

TheSquad
- 7,385
- 8
- 40
- 79
3
votes
1 answer
Monitoring a gen_server
I have been trying to monitor a gen_server using erlang:monitor/2. Unfortunately every time I try this the Erlang shell goes into an infinite loop.
Here is the test program i've written to test this…

Brendan Cutajar
- 697
- 6
- 14
3
votes
1 answer
gen_server:call every X seconds
The Status of the gen_server is a list and should be processed once every X seconds. Therefore, I need to execute handle_call({process},State) every X seconds.
What is the best way to have a handle_call executed every X seconds?

Daniel
- 20,420
- 10
- 92
- 149
3
votes
1 answer
DynamicSupervisor.start_child(...) ----> error > already started
I have this code:
defmodule MyApp.JobRunner do
use DynamicSupervisor
alias MyApp.MyWorker
def start_link(_arg) do
DynamicSupervisor.start_link(__MODULE__, :ok, name: __MODULE__)
end
def init(:ok) do
IO.puts("MyApp.JobRunner:…

Koklushkin
- 155
- 7
3
votes
1 answer
Stop a GenServer after each test
Background
I have a set of tests that need a GenServer to be started before. As a rule of thumb, I understand it is a good practice to cleanup after each test, so I also want to stop the GenServer after each test.
Problem
The problem here is that I…

Flame_Phoenix
- 16,489
- 37
- 131
- 266
3
votes
1 answer
Correct GenServer implementation with persistent state
I am new to some OTP concepts. I have GenServer, that will Publish events to RabbitMQ. This GenServer has the state: amqp Chanel which is initiates once during init() and is persistent between cast invokes.
defmodule Myapp.Events.AmqpTransport do
…

Rudziankoŭ
- 10,681
- 20
- 92
- 192
3
votes
0 answers
Where to put a global gen_server when dividing system into OTP apps?
TL;DR
If OTP application A makes calls to a globally registered gen_server in application B, and I don't want to install all of app B on nodes that don't run it, how do I handle the gen_servers client code?
Background (slightly simplified)
I have a…

vmdm
- 69
- 4
3
votes
1 answer
Getting the PID of a scenic component/scene
Quick question, in the Scenic docs it suggests that you can interact with any scene as you would any GenServer:
You are free to send your own messages to scenes just as you would
with any other GenServer process. You can use the handle_info/2…

Tom Haines
- 123
- 3
- 9
3
votes
2 answers
Erlang stop gen_server
I have gen_server:
start(UserName) ->
case gen_server:start({global, UserName}, player, [], []) of
{ok, _} ->
io:format("Player: " ++ UserName ++ " started");
{error, Error} ->
Error
end
...
Now i want to write…

0xAX
- 20,957
- 26
- 117
- 206
3
votes
1 answer
Elixir non-blocking threads on a GenServer?
I'm trying to accomplish a simple task but I'm having huge difficulties.
Please suppose I have a GenServer, and one of its callbacks is as follows:
@impl true
def handle_call(:state, _, state) do
# Something that would require 10 seconds
…

deko
- 463
- 1
- 6
- 17
3
votes
1 answer
Memory leaks from GenServer processes
I have been into a little trouble lately: The memory used by GenServer processes is super high, probably because of large binary leaks.
The problem comes from here: we receive large binaries through the GenServer and we pass them to the consumer,…

ShaH
- 170
- 1
- 9