Skip to content

Commit

Permalink
Merge branch 'anders/diameter/missed_events/OTP-9824' into maint
Browse files Browse the repository at this point in the history
* anders/diameter/missed_events/OTP-9824:
  Update watchdog suite
  Ensure capabilities exchange can't fail too early
  • Loading branch information
Anders Svensson committed Dec 20, 2011
2 parents 40d5714 + 8a7b17a commit 0610ab2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 22 deletions.
20 changes: 11 additions & 9 deletions lib/diameter/src/base/diameter_service.erl
Expand Up @@ -629,10 +629,6 @@ insert(Tbl, Rec) ->
ets:insert(Tbl, Rec), ets:insert(Tbl, Rec),
Rec. Rec.


monitor(Pid) ->
erlang:monitor(process, Pid),
Pid.

%% Using the process dictionary for the callback state was initially %% Using the process dictionary for the callback state was initially
%% just a way to make what was horrendous trace (big state record and %% just a way to make what was horrendous trace (big state record and
%% much else everywhere) somewhat more readable. There's not as much %% much else everywhere) somewhat more readable. There's not as much
Expand Down Expand Up @@ -814,10 +810,10 @@ start(Ref, Type, Opts, #state{peerT = PeerT,
service = Svc}) service = Svc})
when Type == connect; when Type == connect;
Type == accept -> Type == accept ->
Pid = monitor(s(Type, Ref, {ConnT, Pid = s(Type, Ref, {ConnT,
Opts, Opts,
SvcName, SvcName,
merge_service(Opts, Svc)})), merge_service(Opts, Svc)}),
insert(PeerT, #peer{pid = Pid, insert(PeerT, #peer{pid = Pid,
type = Type, type = Type,
ref = Ref, ref = Ref,
Expand All @@ -830,7 +826,13 @@ start(Ref, Type, Opts, #state{peerT = PeerT,
%% callbacks. %% callbacks.


s(Type, Ref, T) -> s(Type, Ref, T) ->
diameter_watchdog:start({Type, Ref}, T). case diameter_watchdog:start({Type, Ref}, T) of
{_MRef, Pid} ->
Pid;
Pid when is_pid(Pid) -> %% from old code
erlang:monitor(process, Pid),
Pid
end.


%% merge_service/2 %% merge_service/2


Expand Down
40 changes: 32 additions & 8 deletions lib/diameter/src/base/diameter_watchdog.erl
Expand Up @@ -59,10 +59,19 @@
message_data}). %% term passed into diameter_service with message message_data}). %% term passed into diameter_service with message


%% start/2 %% start/2
%%
%% Start a monitor before the watchdog is allowed to proceed to ensure
%% that a failed capabilities exchange produces the desired exit
%% reason.


start({_,_} = Type, T) -> start({_,_} = Type, T) ->
{ok, Pid} = diameter_watchdog_sup:start_child({Type, self(), T}), Ref = make_ref(),
Pid. {ok, Pid} = diameter_watchdog_sup:start_child({Ref, {Type, self(), T}}),
try
{erlang:monitor(process, Pid), Pid}
after
Pid ! Ref
end.


start_link(T) -> start_link(T) ->
{ok, _} = proc_lib:start_link(?MODULE, {ok, _} = proc_lib:start_link(?MODULE,
Expand All @@ -80,14 +89,29 @@ init(T) ->
proc_lib:init_ack({ok, self()}), proc_lib:init_ack({ok, self()}),
gen_server:enter_loop(?MODULE, [], i(T)). gen_server:enter_loop(?MODULE, [], i(T)).


i({T, Pid, {ConnT, Opts, SvcName, #diameter_service{applications = Apps, i({Ref, {_, Pid, _} = T}) ->
capabilities = Caps} MRef = erlang:monitor(process, Pid),
= Svc}}) -> receive
{M,S,U} = now(), Ref ->
random:seed(M,S,U), make_state(T);
{'DOWN', MRef, process, _, _} = D ->
exit({shutdown, D})
end;

i({_, Pid, _} = T) -> %% from old code
erlang:monitor(process, Pid),
make_state(T).

make_state({T, Pid, {ConnT,
Opts,
SvcName,
#diameter_service{applications = Apps,
capabilities = Caps}
= Svc}}) ->
random:seed(now()),
putr(restart, {T, Opts, Svc}), %% save seeing it in trace putr(restart, {T, Opts, Svc}), %% save seeing it in trace
putr(dwr, dwr(Caps)), %% putr(dwr, dwr(Caps)), %%
#watchdog{parent = monitor(Pid), #watchdog{parent = Pid,
transport = monitor(diameter_peer_fsm:start(T, Opts, Svc)), transport = monitor(diameter_peer_fsm:start(T, Opts, Svc)),
tw = proplists:get_value(watchdog_timer, tw = proplists:get_value(watchdog_timer,
Opts, Opts,
Expand Down
11 changes: 6 additions & 5 deletions lib/diameter/test/diameter_watchdog_SUITE.erl
Expand Up @@ -306,11 +306,8 @@ watchdog(Type, Ref, TPid, Wd) ->
Opts = [{transport_module, ?MODULE}, Opts = [{transport_module, ?MODULE},
{transport_config, TPid}, {transport_config, TPid},
{watchdog_timer, Wd}], {watchdog_timer, Wd}],
monitor(diameter_watchdog:start({Type, Ref}, {_MRef, Pid} = diameter_watchdog:start({Type, Ref},
{false, Opts, false, ?SERVICE})). {false, Opts, false, ?SERVICE}),

monitor(Pid) ->
erlang:monitor(process, Pid),
Pid. Pid.


%% =========================================================================== %% ===========================================================================
Expand Down Expand Up @@ -350,6 +347,10 @@ init(_, _, TPid, _) ->
monitor(TPid), monitor(TPid),
3. 3.


monitor(Pid) ->
erlang:monitor(process, Pid),
Pid.

%% Generate a unique hostname for the faked peer. %% Generate a unique hostname for the faked peer.
hostname() -> hostname() ->
lists:flatten(io_lib:format("~p-~p-~p", tuple_to_list(now()))). lists:flatten(io_lib:format("~p-~p-~p", tuple_to_list(now()))).
Expand Down

0 comments on commit 0610ab2

Please sign in to comment.