sysashi

sysashi

Stopping/exiting GenServer process

I have a gen server spawned by simple one for one supervisor, and when I return {:stop, {:shutdown, reason}, state} process remains alive, even though terminate/2 callback is called. What am I doing wrong? (if instead of returning :stop tuple I call Supervisor.terminate_child(MySupervisor, self()) process terminates as expected. How do I stop it, and what is the right way?

Marked As Solved

idi527

idi527

Does it actually remain alive (same pid), or does it get restarted?

Also Liked

dom

dom

It doesn’t keep state, but it uses the same start function and arguments, so if your initialization is deterministic the process will end up in the same state.

http://erlang.org/doc/man/supervisor.html#start_child-2

For a simple_one_for_one supervisor, the child specification defined in Module:init/1 is used, and ChildSpec must instead be an arbitrary list of terms List. The child process is then started by appending List to the existing start function arguments, that is, by calling apply(M, F, A++List), where {M,F,A} is the start function defined in the child specification.

dom

dom

It’s not possible for a gen_server to go back to loop after terminate is called. Are you really sure terminate was called, and the process wasn’t restarted?

NobbZ

NobbZ

How was the child initialised? What’s it restart value? Permanent, temporary or transient?

kokolegorille

kokolegorille

Is it a call or a cast? I remember having some troubles with the response tupple. Maybe try to change your return value.

There is a call return

{:stop, :normal, state, state}

There is a cast return

{:stop, :normal, state}

BTW simple_one_for_one is going to be deprecated in favor of Dynamic Supervisor. I also had syntax problem, dialyzer warning because of it. simple_one_for_one does not accept new child_spec.

sysashi

sysashi

I’m sorry I’ve wasted your time folks, process is being restarted (Initially I’ve checked the state of the process, and for my surprise state remained from the previous process, so I thought it’s the same one, next I checked observer to verify that pid does not change and it’s the same process, but it actually has changed and new pid was a digit different from the previous one so I did not notice at first… :persevere:)
Later I set restart to temporary and it worked as intended (as @NobbZ pointed out).

One question though, does supervisor keeps initial state of the process? Because said process being restarted with the same state I initialised the previous one.

Where Next?

Popular in Questions Top

pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

Other popular topics Top

JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement