[erlang-questions] initializing process
Fri Sep 18 02:26:10 CEST 2009
What exactly are you trying to do? It's really easy to create complex
race conditions and strange startup ordering issues doing something
If you can have the node signal you (much less work). Just start out
in an "uninitialized" state set a short timeout and just go idle.
When you receive the "other_node_started" event, go into "running"
mode. I'd recommend using sync_send_event from the server you're
waiting on. That guarantees to close the loop in case they start up
in a weird order.
Timeouts are handy and highly underutilized. Other great uses include
"forcibly garbage collecting during inactivity" and "delaying before
If you must ping the node from the waiting side, you can simulate a
delaying loop with a gen_server (and a gen_fsm) by using the timeout
feature. Just send the ping and set a timeout. Have the timeout
function send the ping again and set a timeout again. Eventually,
you'll get the response and can go about your merry way.
Both of these methods prevent you from sitting in init for an
undefined amount of time.
All of this gets complicated in the face of restarts. It may not
really be workable. It would help to know more about what you're doing.
I think the "correct" way (i.e. overkill in the style of Ericsson) is
to do this at an application level. You can set up a distributed
Erlang application to start in "phases". Depending on your
deployment, that might be the ultimate answer, since it also provides
hooks for takeover / failover, which may be necessary depending on
On Sep 17, 2009, at 8:48 AM, paweł kamiński wrote:
> can somebody corrects me (and hopefully help with my problem).
> so the problem is like that
> 1)Im starting a server in erlang and among others I create one
> process that
> needs to decide if another local computer is up before whole server's
> initialization process is done.
> 2)the process is simple gen_server
> (AND HERE IS A PROBLEM)
> 3)as long as I dont return from init/1 fun, my process is not seen
> (I cant
> really use self() - is that correct??) by others so I CANT RECEIVE ANY
> MESSAGES. so I though I can spawn another processes while in init/1
> will loop and ping another side if it is ready. but I am afraid that
> might be a chance that the gen_server will not yet return from init
> spawned worker will try to send some notification, so or I will miss
> it or
> there will be some error.
> is this really a problem or Im just missing something here that is so
> All I really need is to init state of the gen_server, then start
> initializing the server so I cant hard code all conditions in init
> fun and I
> need to communicate with other processes.
> hope it is more or less clear
> take care
> Paweł Kamiński
More information about the erlang-questions