]> granicus.if.org Git - ejabberd/commitdiff
Process gen_server timeouts correctly
authorEvgeniy Khramtsov <ekhramtsov@process-one.net>
Thu, 1 May 2014 16:43:51 +0000 (20:43 +0400)
committerEvgeniy Khramtsov <ekhramtsov@process-one.net>
Fri, 2 May 2014 13:40:25 +0000 (17:40 +0400)
src/mod_sip_registrar.erl

index 3e65564c1a57dc13d9e91e2488a5a0015000d9fa..386391327b4dad34b97b8dc90a06b4a4ee23f627 100644 (file)
@@ -22,6 +22,8 @@
 -include("logger.hrl").
 -include("esip.hrl").
 
+-define(CALL_TIMEOUT, timer:seconds(30)).
+
 -record(binding, {socket = #sip_socket{},
                  call_id = <<"">> :: binary(),
                  cseq = 0 :: non_neg_integer(),
@@ -190,11 +192,11 @@ register_session(US, SIPSocket, CallID, CSeq, Expires) ->
                                                cseq = CSeq,
                                                timestamp = now(),
                                                expires = Expires}]},
-    gen_server:call(?MODULE, {write, Session}).
+    call({write, Session}).
 
 unregister_session(US, SIPSocket, CallID, CSeq) ->
     Msg = {delete, US, SIPSocket, CallID, CSeq},
-    gen_server:call(?MODULE, Msg).
+    call(Msg).
 
 write_session(#sip_session{us = US,
                           bindings = [#binding{socket = SIPSocket,
@@ -289,9 +291,21 @@ pop_previous_binding(#sip_socket{peer = Peer}, Bindings) ->
            {error, notfound}
     end.
 
+call(Msg) ->
+    case catch ?GEN_SERVER:call(?MODULE, Msg, ?CALL_TIMEOUT) of
+       {'EXIT', {timeout, _}} ->
+           {error, timeout};
+       {'EXIT', Why} ->
+           {error, Why};
+       Reply ->
+           Reply
+    end.
+
 make_status(notfound) ->
     {404, esip:reason(404)};
 make_status(cseq_out_of_order) ->
     {500, <<"CSeq is Out of Order">>};
+make_status(timeout) ->
+    {408, esip:reason(408)};
 make_status(_) ->
     {500, esip:reason(500)}.