Permalink
Browse files

Restart a gen_server proc when some error occured

  • Loading branch information...
mocchira committed Jan 31, 2014
1 parent 34ab240 commit c9b477886e3017dec99f16ee8995910403ef850a
Showing with 8 additions and 6 deletions.
  1. +8 −6 src/leo_rpc_client_conn.erl
@@ -175,18 +175,18 @@ exec(Req, From, #state{socket = undefined} = State) ->
ok ->
{noreply, State1#state{pid_from = From}};
{error, Reason} ->
- {reply, {error, Reason}, State1}
+ {stop, Reason, {error, Reason}, State1}
end;
{error, Reason} ->
- {reply, {error, Reason}, State}
+ {stop, Reason, {error, Reason}, State}
end;
exec(Req, From, #state{socket = Socket} = State) ->
case gen_tcp:send(Socket, Req) of
ok ->
{noreply, State#state{pid_from = From}};
{error, Reason} ->
- {reply, {error, Reason}, State}
+ {stop, Reason, {error, Reason}, State}
end.
@@ -195,13 +195,15 @@ exec(Req, From, #state{socket = Socket} = State) ->
-spec(handle_response(binary(), #state{}) ->
#state{}).
handle_response(Data, #state{pid_from = From,
- socket = Socket,
+ socket = _Socket,
nreq = NumReq} = State) ->
reply(Data, From),
case NumReq of
?MAX_REQ_PER_CON ->
- catch gen_tcp:close(Socket),
- State#state{pid_from = undefined, socket = undefined, nreq = 0};
+ %% for debug
+ State#state{pid_from = undefined, nreq = NumReq + 1};
+ %catch gen_tcp:close(Socket),
+ %State#state{pid_from = undefined, socket = undefined, nreq = 0};
_ ->
State#state{pid_from = undefined, nreq = NumReq + 1}
end.

0 comments on commit c9b4778

Please sign in to comment.