]> granicus.if.org Git - ejabberd/commitdiff
added get_random_pid/1 error handling
authorHAMANO Tsukasa <hamano@cuspy.org>
Thu, 24 Apr 2014 06:34:41 +0000 (15:34 +0900)
committerHAMANO Tsukasa <hamano@cuspy.org>
Thu, 24 Apr 2014 06:34:41 +0000 (15:34 +0900)
src/ejabberd_odbc.erl
src/ejabberd_odbc_sup.erl

index 6a7d9de6d9263b96056a05ae31234f262c50e9bf..802e32ae274fc03571804cb38572f6d88896e16c 100644 (file)
@@ -140,9 +140,12 @@ sql_bloc(Host, F) -> sql_call(Host, {sql_bloc, F}).
 sql_call(Host, Msg) ->
     case get(?STATE_KEY) of
       undefined ->
-         (?GEN_FSM):sync_send_event(ejabberd_odbc_sup:get_random_pid(Host),
-                                    {sql_cmd, Msg, now()},
-                                    ?TRANSACTION_TIMEOUT);
+        case ejabberd_odbc_sup:get_random_pid(Host) of
+          none -> ?WARNING_MSG("SQL calling unknown host: ~p~n", [Host]);
+          Pid ->
+            (?GEN_FSM):sync_send_event(Pid,{sql_cmd, Msg, now()},
+                                       ?TRANSACTION_TIMEOUT)
+          end;
       _State -> nested_op(Msg)
     end.
 
index bfad5428e4d7df9c7daacb63d5b9831c9cb1f71b..d05fd139e67d26be2275056ade8a738d569bb74e 100644 (file)
@@ -82,8 +82,10 @@ get_pids(Host) ->
     [R#sql_pool.pid || R <- Rs].
 
 get_random_pid(Host) ->
-    Pids = get_pids(Host),
-    lists:nth(erlang:phash(now(), length(Pids)), Pids).
+    case get_pids(Host) of
+      [] -> none;
+      Pids -> lists:nth(erlang:phash(now(), length(Pids)), Pids)
+    end.
 
 add_pid(Host, Pid) ->
     F = fun () ->