mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-26 17:38:45 +01:00
Clean up all timers gracefully
This commit is contained in:
parent
ddfbca5830
commit
12ab5a749f
@ -271,13 +271,7 @@ write_session([#sip_session{us = {U, S} = US}|_] = NewSessions,
|
|||||||
if length(AllSessions) > MaxSessions ->
|
if length(AllSessions) > MaxSessions ->
|
||||||
{error, too_many_sessions};
|
{error, too_many_sessions};
|
||||||
true ->
|
true ->
|
||||||
lists:foreach(
|
lists:foreach(fun delete_session/1, DelSessions),
|
||||||
fun(#sip_session{reg_tref = TRef,
|
|
||||||
conn_mref = MRef} = Session) ->
|
|
||||||
erlang:cancel_timer(TRef),
|
|
||||||
catch erlang:demonitor(MRef, [flush]),
|
|
||||||
mnesia:dirty_delete_object(Session)
|
|
||||||
end, DelSessions),
|
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun(Session) ->
|
fun(Session) ->
|
||||||
NewSession = set_monitor_and_timer(
|
NewSession = set_monitor_and_timer(
|
||||||
@ -308,12 +302,10 @@ delete_session(US, CallID, CSeq) ->
|
|||||||
true ->
|
true ->
|
||||||
ContactsWithExpires =
|
ContactsWithExpires =
|
||||||
lists:map(
|
lists:map(
|
||||||
fun(#sip_session{contact = Contact,
|
fun(#sip_session{contact = Contact} = Session) ->
|
||||||
reg_tref = TRef}) ->
|
delete_session(Session),
|
||||||
erlang:cancel_timer(TRef),
|
|
||||||
{Contact, 0}
|
{Contact, 0}
|
||||||
end, Sessions),
|
end, Sessions),
|
||||||
mnesia:dirty_delete(sip_session, US),
|
|
||||||
{ok, ContactsWithExpires};
|
{ok, ContactsWithExpires};
|
||||||
false ->
|
false ->
|
||||||
{error, cseq_out_of_order}
|
{error, cseq_out_of_order}
|
||||||
@ -329,7 +321,7 @@ delete_expired_session(US, TRef) ->
|
|||||||
fun(#sip_session{reg_tref = T1,
|
fun(#sip_session{reg_tref = T1,
|
||||||
flow_tref = T2} = Session)
|
flow_tref = T2} = Session)
|
||||||
when T1 == TRef; T2 == TRef ->
|
when T1 == TRef; T2 == TRef ->
|
||||||
mnesia:dirty_delete_object(Session);
|
delete_session(Session);
|
||||||
(_) ->
|
(_) ->
|
||||||
ok
|
ok
|
||||||
end, Sessions);
|
end, Sessions);
|
||||||
@ -526,6 +518,14 @@ set_monitor_and_timer(#sip_session{socket = #sip_socket{type = Type,
|
|||||||
set_timer(#sip_session{us = US}, Timeout) ->
|
set_timer(#sip_session{us = US}, Timeout) ->
|
||||||
erlang:start_timer(Timeout * 1000, self(), US).
|
erlang:start_timer(Timeout * 1000, self(), US).
|
||||||
|
|
||||||
|
delete_session(#sip_session{reg_tref = RegTRef,
|
||||||
|
flow_tref = FlowTRef,
|
||||||
|
conn_mref = MRef} = Session) ->
|
||||||
|
erlang:cancel_timer(RegTRef),
|
||||||
|
catch erlang:cancel_timer(FlowTRef),
|
||||||
|
catch erlang:demonitor(MRef, [flush]),
|
||||||
|
mnesia:dirty_delete_object(Session).
|
||||||
|
|
||||||
process_ping(SIPSocket) ->
|
process_ping(SIPSocket) ->
|
||||||
ErrResponse = if SIPSocket#sip_socket.type == udp -> error;
|
ErrResponse = if SIPSocket#sip_socket.type == udp -> error;
|
||||||
true -> drop
|
true -> drop
|
||||||
|
Loading…
Reference in New Issue
Block a user