Skip to content

Commit

Permalink
Session handling bug in socket reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
uwiger committed Nov 27, 2012
1 parent 2994e82 commit 148b6fb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/exo_socket_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ handle_info({inet_async, LSocket, Ref, {ok,Socket}} = _Msg, State) when
{stop, Reason, State}
end;
%% handle {ok,Socket} on bad ref ?
handle_info({inet_async, _LSocket, Ref, {error,Reason}}, State) when
handle_info({inet_async, _LSocket, Ref, {error,Reason}}, State) when
Ref =:= State#state.ref ->
case exo_socket:async_accept(State#state.listen) of
{ok,Ref} ->
Expand All @@ -277,8 +277,12 @@ handle_info({inet_async, _LSocket, Ref, {error,Reason}}, State) when
end;
handle_info({Pid, ?MODULE, connected, Host, Port},
#state{socket_reuse = #reuse{sessions = Sessions} = R} = State) ->
{_, Pending} = dict:fetch(Key = {Host, Port}, Sessions),
[gen_server:reply(From, Pid) || From <- Pending],
Session = dict:fetch(Key = {Host, Port}, Sessions),
case Session of
{_, Pending} ->
[gen_server:reply(From, Pid) || From <- Pending];
_ -> ok
end,
Sessions1 = dict:store(Key, Pid, Sessions),
%% Pids = dict:store(Pid, {Host,Port}, R#reuse.session_pids),
R1 = R#reuse{sessions = Sessions1},
Expand Down Expand Up @@ -311,8 +315,12 @@ handle_info({'DOWN', _, process, Pid, _},
error ->
{noreply, State};
{ok, {_Host,_Port} = Key} ->
{_, Pending} = dict:fetch(Key, Sessions),
[gen_server:reply(From, rejected) || From <- Pending],
Session = dict:fetch(Key, Sessions),
case Session of
{_, Pending} ->
[gen_server:reply(From, rejected) || From <- Pending];
_ -> ok
end,
Sessions1 = dict:erase(Key, Sessions),
Pids1 = dict:erase(Pid, Pids),
R1 = R#reuse{sessions = Sessions1, session_pids = Pids1},
Expand Down

0 comments on commit 148b6fb

Please sign in to comment.