Skip to content

Commit

Permalink
Deal with the fact that capabilities config may be incomplete
Browse files Browse the repository at this point in the history
A transport can be configured before its service so handle
insufficient configuration instead of crashing at CER/CEA encode.
  • Loading branch information
Anders Svensson committed Aug 23, 2012
1 parent cfea5ee commit 1c38848
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/diameter/src/base/diameter_codec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ encode(Mod, #diameter_packet{} = Pkt) ->
e(Mod, Pkt)
catch
error: Reason ->
%% Be verbose rather than letting the emulator truncate the
%% error report.
X = {Reason, ?STACK},
%% Be verbose since a crash report may be truncated and
%% encode errors are self-inflicted.
X = {?MODULE, encode, {Reason, ?STACK}},
diameter_lib:error_report(X, {?MODULE, encode, [Mod, Pkt]}),
exit(X)
end;
Expand Down
15 changes: 14 additions & 1 deletion lib/diameter/src/base/diameter_peer_fsm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,27 @@ handle_info(T, #state{} = State) ->
?LOG(stop, T),
x(T, State)
catch
exit: {diameter_codec, encode, _} = Reason ->
close_wd(Reason, State#state.parent),
?LOG(stop, Reason),
%% diameter_codec:encode/2 emits an error report. Only
%% indicate the probable reason here.
diameter_lib:info_report(probable_configuration_error,
insufficient_capabilities),
{stop, {shutdown, Reason}, State};
{?MODULE, Tag, Reason} ->
?LOG(Tag, {Reason, T}),
{stop, {shutdown, Reason}, State}
end.
%% The form of the exception caught here is historical. It's
%% The form of the throw caught here is historical. It's
%% significant that it's not a 2-tuple, as in ?FAILURE(Reason),
%% since these are caught elsewhere.

%% Note that there's no guarantee that the service and transport
%% capabilities are good enough to build a CER/CEA that can be
%% succesfully encoded. It's not checked at diameter:add_transport/2
%% since this can be called before creating the service.

x(Reason, #state{} = S) ->
close_wd(Reason, S),
{stop, {shutdown, Reason}, S}.
Expand Down

0 comments on commit 1c38848

Please sign in to comment.