From e23e5ef549294feadf3477f8365030e0501ea58c Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Tue, 10 Mar 2015 16:59:11 -0400 Subject: [PATCH] Errors in fsm should not crash server Problems starting or sending data to the client fsm should not crash the main seds server. --- src/seds.erl | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/seds.erl b/src/seds.erl index e96d960..38f67ec 100644 --- a/src/seds.erl +++ b/src/seds.erl @@ -98,15 +98,23 @@ handle_call({send, {IP, Port, #dns_rec{} = Rec, Session = session(Query, State), case dict:find(Session, Proxies) of error when Sum == 0 -> - {ok, Proxy} = proxy(Session, State), - ok = seds_proxy:send(Proxy, IP, Port, Rec, Dir, 0, Data), - {reply, ok, State#state{ - p = dict:store(Session, Proxy, Proxies) - }}; + P = try + {ok, Proxy} = proxy(Session, State), + ok = seds_proxy:send(Proxy, IP, Port, Rec, Dir, 0, Data), + dict:store(Session, Proxy, Proxies) + catch + _:_ -> + Proxies + end, + {reply, ok, State#state{p = P}}; error -> {reply, ok, State}; {ok, Proxy} -> - ok = seds_proxy:send(Proxy, IP, Port, Rec, Dir, Sum, Data), + try + ok = seds_proxy:send(Proxy, IP, Port, Rec, Dir, Sum, Data) + catch + _:_ -> ok + end, {reply, ok, State} end;