gen_server init returns {stop, Reason} and fails: possibly doc bug?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

gen_server init returns {stop, Reason} and fails: possibly doc bug?

Max Lapshin-2

Here:  http://erlang.org/doc/man/gen_server.html#start_link-3  we can read that start_link will return  {error, Reason} if init callback returns {stop, Reason}


Maybe I'm wrong, but it seems that it is not possible to get back clean reply, because gen_server.erl  has following code:

proc_lib:init_ack(Starter, {error, Reason}),  % here we may receive error tuple
exit(Reason)  

After exit caller is failing because of linkage. So if we want to have start_link, we cannot get clean logs and clearly get {error, Reason}  tuple.

Am I wrong?

_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: gen_server init returns {stop, Reason} and fails: possibly doc bug?

Brujo Benavides-2
You’re correct.
To be able to use the result of gen_server:start_link you must be trapping exits.
I wrote a blog post about it a while back.
Cheers!

On May 2, 2017, at 11:57, Max Lapshin <[hidden email]> wrote:


Here:  http://erlang.org/doc/man/gen_server.html#start_link-3  we can read that start_link will return  {error, Reason} if init callback returns {stop, Reason}


Maybe I'm wrong, but it seems that it is not possible to get back clean reply, because gen_server.erl  has following code:

proc_lib:init_ack(Starter, {error, Reason}),  % here we may receive error tuple
exit(Reason)  

After exit caller is failing because of linkage. So if we want to have start_link, we cannot get clean logs and clearly get {error, Reason}  tuple.

Am I wrong?
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions


_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Loading...