[erlang-bugs] sys:get_status kills gen_servers registered globally with something other than an atom

Björn Gustavsson bgustavsson@REDACTED
Tue May 4 08:27:26 CEST 2010


2010/4/30 Paul Hampson <PaulH@REDACTED>:
> Using Erlang R13B04, I'm creating gen_servers with gen_server:start( { global, "Name" } ). This is valid according to the gen_server manpage, which states GlobalName is term().
>
> However, if I call sys:get_status({global, "Name"}) (or sys_get:status( global:whereis_name( "Name" ) ) to rule out the name lookup as an issue) the gen_server dies, with:
>
>    exception error: no true branch found when evaluating an if expression
>      in function  gen_server:format_status/2
>      in call from sys:get_status/5
>      in call from sys:do_cmd/6
>      in call from sys:handle_system_msg/8
>
> This is because of the following code in gen_server:format_status:
>
>    NameTag = if is_pid(Name) ->
>              pid_to_list(Name);
>         is_atom(Name) ->
>              Name
>          end,
>    Header = lists:concat(["Status for generic server ", NameTag]),
>
> Which fails to handle that Name (which is stripped of {global,} in gen_server:name/1 or gen_server:get_proc_name/1) may be something other than an atom or pid.
>
> Interestingly, the comment above gen_server:start/3 indicates that the supplied server name is { global, atom() }, not { global, term() } as per the documentation.
>
> So either the documentation is wrong, or the gen_server implementation/comment is wrong.
>
> Bizarrely, I'm sure I was able to use sys:get_status against these same gen_servers a month ago, which would have been R13B03 or maybe an B13B03, but erlang/otp on github doesn't indicate any relevant changes.

The relevant change is in sys.erl in this commit:

http://github.com/erlang/otp/commit/88b530ea24977081020feb2123124063e58dfc12

The gen_server:format_status/2 function did not get called before that change.
Since that change introduces useful functionality, we don't plan to revert it,
but to fix the damage in R14.

One way to fix that would problem could be simply to change the
code for calculating NameTag to:

    NameTag = if is_pid(Name) ->
		      pid_to_list(Name);
		 _ ->
		      Name
	      end,

-- 
Björn Gustavsson, Erlang/OTP, Ericsson AB


More information about the erlang-bugs mailing list