Skip to content

Commit

Permalink
Merge branch 'gustav/stdlib/gen_server_enter_loop_global_scope/OTP-10…
Browse files Browse the repository at this point in the history
…130' into maint

* gustav/stdlib/gen_server_enter_loop_global_scope/OTP-10130:
  Change testcase of gen_server:enter_loop/4 with global scope to match on result of a gen_server:call/2
  Correct guard matching in gen_server:enter_loop/4 to match global scope in ServerName without timeout.
  • Loading branch information
Gustav Simonsson committed Jul 10, 2012
2 parents c075ac6 + 30fe2fc commit eac9c34
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/stdlib/src/gen_server.erl
Expand Up @@ -270,7 +270,7 @@ enter_loop(Mod, Options, State) ->
enter_loop(Mod, Options, State, self(), infinity).

enter_loop(Mod, Options, State, ServerName = {Scope, _})
when Scope == local; Scope == local ->
when Scope == local; Scope == global ->
enter_loop(Mod, Options, State, ServerName, infinity);

enter_loop(Mod, Options, State, ServerName = {via, _, _}) ->
Expand Down
22 changes: 20 additions & 2 deletions lib/stdlib/test/gen_server_SUITE.erl
Expand Up @@ -37,7 +37,8 @@

% spawn export
-export([spec_init_local/2, spec_init_global/2, spec_init_via/2,
spec_init_default_timeout/2, spec_init_anonymous/1,
spec_init_default_timeout/2, spec_init_global_default_timeout/2,
spec_init_anonymous/1,
spec_init_anonymous_default_timeout/1,
spec_init_not_proc_lib/1, cast_fast_messup/0]).

Expand Down Expand Up @@ -749,7 +750,7 @@ spec_init(suite) ->
spec_init(Config) when is_list(Config) ->

OldFlag = process_flag(trap_exit, true),

?line {ok, Pid0} = start_link(spec_init_local, [{ok, my_server}, []]),
?line ok = gen_server:call(Pid0, started_p),
?line ok = gen_server:call(Pid0, stop),
Expand Down Expand Up @@ -819,6 +820,14 @@ spec_init(Config) when is_list(Config) ->
test_server:fail(gen_server_did_not_die)
end,

%% Before the OTP-10130 fix this failed because a timeout message
%% was generated as the spawned process crashed because a {global, Name}
%% was matched as a timeout value instead of matching on scope.
{ok, _PidHurra} =
start_link(spec_init_global_default_timeout, [{ok, hurra}, []]),
timer:sleep(1000),
ok = gen_server:call(_PidHurra, started_p),

?line Pid5 =
erlang:spawn_link(?MODULE, spec_init_not_proc_lib, [[]]),
receive
Expand Down Expand Up @@ -1125,6 +1134,15 @@ spec_init_default_timeout({ok, Name}, Options) ->
%% Supervised init can occur here ...
gen_server:enter_loop(?MODULE, Options, {}, {local, Name}).

%% OTP-10130, A bug was introduced where global scope was not matched when
%% enter_loop/4 was called (no timeout).
spec_init_global_default_timeout({ok, Name}, Options) ->
process_flag(trap_exit, true),
global:register_name(Name, self()),
proc_lib:init_ack({ok, self()}),
%% Supervised init can occur here ...
gen_server:enter_loop(?MODULE, Options, {}, {global, Name}).

spec_init_anonymous(Options) ->
process_flag(trap_exit, true),
proc_lib:init_ack({ok, self()}),
Expand Down

0 comments on commit eac9c34

Please sign in to comment.