Questions tagged [gen-server]

gen_server stands for "generic server", a module behaviour in Erlang.

315 questions
8
votes
1 answer

'handle_call' getting timed out

i am calling elixir genserver from handle info function in GenServer to add phone-number getting form client. But as soon as handle_call is called owner process gets crashed [timeout]. Please help. One ETS is created globally to insert values…
NewBee
  • 195
  • 8
7
votes
2 answers

Erlang gen_server with long-running tasks

Good day, I have a gen_server process which does some long-running state-updating tasks periodically in handle_info: handle_info(trigger, State) -> NewState = some_long_running_task(), erlang:send_after(?LOOP_TIME, self(), trigger), …
Dfr
  • 4,075
  • 10
  • 40
  • 63
7
votes
1 answer

How to describe gen_server visually?

Disclaimer: The author is a newbie in OTP having some basic knowledge of Erlang's syntax, processes and messages. I am trying to grasp the notion of behaviours in Erlang, but a lot of questions spring in my head preventing me from understanding the…
skanatek
  • 5,133
  • 3
  • 47
  • 75
7
votes
2 answers

Erlang: Best way for a singleton gen_server in erlang cluster?

Setting: I want to start a unique global registered gen_server process in an erlang cluster. If the process is stopped or the node running it goes down, the process is to be started on one of the other nodes. The process is part of a supervisor.…
Rumpelstilz
  • 267
  • 2
  • 7
7
votes
2 answers

Trouble Understanding Erlang Gen_Server Architecture

I am in early stages of learning Erlang and I need some further assistance. Not sure if this will get any sunlight but here it goes ... I am looking for a flow diagram on how the example works. Example…
user954753
  • 309
  • 1
  • 3
  • 14
7
votes
2 answers

Unsupervised gen_server doesn't call terminate when it receives exit signal

gen_server documentation on Module:terminate callback says: Even if the gen_server process is not part of a supervision tree, this function is called if it receives an 'EXIT' message from its parent. Reason is the same as in the 'EXIT'…
Majid Azimi
  • 5,575
  • 13
  • 64
  • 113
7
votes
1 answer

How to create many GenServer processes from List and map data stored in them?

In both approaches I stuck on How to map processes by given set of ids or groups and then map stored struct to filter data. %{group => [users]} implementation. I realized that groups will be limited in opposite to users, so I've created one process…
luzny
  • 2,380
  • 7
  • 30
  • 64
7
votes
1 answer

what is the difference between gen_server:cast to gen_server:abcast

When looking at abcast abcast man page, and cast cast man page, I couldn't understand what's the difference between those two. Can someone clarify this to me. Thanks
Matt. Stroh
  • 904
  • 7
  • 16
7
votes
1 answer

Erlang Supervisor Strategy For Restarting Connections to Downed Hosts

I'm using erlang as a bridge between services and I was wondering what advice people had for handling downed connections? I'm taking input from local files and piping them out to AMQP and it's conceivable that the AMQP broker could go down. For…
xrl
  • 2,155
  • 5
  • 26
  • 40
7
votes
2 answers

How to run Elixir Supervisor in escript

I have a mix project with as simple as possible a Supervisor and GenServer. When I call from iex: EchoCmd.Supervisor.start_link([:Hello]) GenServer.call(:echoserver, :echo) GenServer.call(:echoserver, :mumble) GenServer.call(:echoserver,…
10 cls
  • 1,325
  • 2
  • 17
  • 31
7
votes
1 answer

Erlang: how to deal with long running init callback?

I have a gen_server that when started attempts to start a certain number of child processes (usually 10-20) under a supervisor in the supervision tree. The gen_server's init callback invokes supervisor:start_child/2 for each child process needed.…
Stratus3D
  • 4,648
  • 4
  • 35
  • 67
6
votes
4 answers

What happens when a gen_server method gets called simultaneously by two clients?

I have a gen_server module that logs data to a file when a client process sends it data. What happens when two client processes send data at the same time to this module? Will the file operations conflict with each other? The erlang documentation is…
quanticle
  • 4,872
  • 6
  • 32
  • 42
5
votes
1 answer

Erlang gen_server cast bad return value

I try to cast message to a gen_server: gen_server:cast({global, ID}, {watchers}). The handler is: handle_cast({watchers}, State) -> case State#table_state.watchers of [] -> {reply, no_watchers, State}; _ -> {reply,…
0xAX
  • 20,957
  • 26
  • 117
  • 206
5
votes
1 answer

When to use Agent instead of GenServer in Elixir

While reading the documentation of both GenServer and Agent I wondered what are the Use Cases the Agent solves that GenServer cannot? So, when to prefer Agent over GenServer? I know that functions defined in your own agents get executed on the agent…
sebisnow
  • 1,671
  • 17
  • 26
5
votes
1 answer

gen_server:call on a global name that is not registered

I have a gen_server process that registers a global name like this: global:register_name(<<"CLIENT_", NAME/binary>>, self()), Another process is trying to send this process a message using gen_server:call like this: gen_server:call({global,…
ErlangWannabe
  • 153
  • 1
  • 5
1
2
3
20 21