Skip to content

Commit

Permalink
switch session state to stopped after receiving a DIAMETER error
Browse files Browse the repository at this point in the history
This ensures that session do not send termination requests after the session
was stopped by a previous error.
  • Loading branch information
RoadRunnr committed Jan 24, 2023
1 parent 9c38415 commit 2679944
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/ergw_aaa_nasreq.erl
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ handle_aaa(['AAA' | #{'Result-Code' := RC} = Avps], Session0, Events0, _Opts, St
{ok, Session, Events, State};
handle_aaa([Answer | #{'Result-Code' := Code}], Session, Events, _Opts, State)
when Answer =:= 'AAA'; Answer =:= 'answer-message' ->
{{fail, Code}, Session, Events, State};
{{fail, Code}, Session, Events, State#state{state = stopped}};
handle_aaa({error, _} = Result, Session, Events, _Opts, State) ->
{Result, Session, Events, State}.
{Result, Session, Events, State#state{state = stopped}}.

handle_aca(['ACA' | #{'Result-Code' := RC} = Avps], Session0, Events0, _Opts, State)
when RC < 3000 ->
Expand Down
2 changes: 1 addition & 1 deletion src/ergw_aaa_ro.erl
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ handle_cca(['CCA' | #{'Result-Code' := Code} = Avps],
{ok, Session, Events, State};
handle_cca([Answer | #{'Result-Code' := Code}], Session, Events, _Opts, State)
when Answer =:= 'CCA'; Answer =:= 'answer-message' ->
{{fail, Code}, Session, [{stop, {?API, peer_reject}} | Events], State};
{{fail, Code}, Session, [{stop, {?API, peer_reject}} | Events], State#state{state = stopped}};
handle_cca({error, no_connection}, Session, Events,
#{answer_if_down := Answer, answers := Answers} = Opts, State0) ->
{Avps, State} =
Expand Down
1 change: 1 addition & 0 deletions test/diameter_Rf_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ handle_failure(Config) ->
?match({{fail, 3001}, _, _},
ergw_aaa_session:invoke(SId, #{}, {rf, 'Initial'}, SOpts)),

%% a session that has been rejected can not be in a `started` state
?equal([{ergw_aaa_rf, started, 1}], get_session_stats()),

Statistics = diff_stats(Stats0, get_stats(?SERVICE)),
Expand Down
2 changes: 2 additions & 0 deletions test/diameter_nasreq_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ handle_failure(Config) ->

?match({{fail, 3007}, _, _}, ergw_aaa_session:start(Session, #{}, [])),

%% a accounting error is not treated as session stop
?equal([{ergw_aaa_nasreq, started, 1}], get_session_stats()),

?match({{fail, 3007}, _, _}, ergw_aaa_session:stop(Session, #{}, [])),
Expand All @@ -321,6 +322,7 @@ handle_answer_error(Config) ->

?match({{error, 3007}, _, _}, ergw_aaa_session:start(Session, #{}, [])),

%% a accounting error is not treated as session stop
?equal([{ergw_aaa_nasreq, started, 1}], get_session_stats()),

?match({{error, 3007}, _, _}, ergw_aaa_session:stop(Session, #{}, [])),
Expand Down

0 comments on commit 2679944

Please sign in to comment.