Permalink
Browse files

fix race condition in recorder (TSUN-218)

  • Loading branch information...
1 parent 94745f1 commit 839efc2fdbe88f6241996e4ecdbd2acfd03171d7 @nniclausse nniclausse committed Sep 10, 2012
Showing with 12 additions and 3 deletions.
  1. +9 −1 src/tsung_recorder/ts_client_proxy.erl
  2. +3 −2 src/tsung_recorder/ts_proxy_listener.erl
@@ -45,7 +45,7 @@
%%--------------------------------------------------------------------
%% External exports
--export([start/1]).
+-export([start/1, set_active/1]).
%% gen_server callbacks
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
@@ -61,6 +61,10 @@
start(Socket) ->
gen_server:start_link(?MODULE, [Socket], []).
+%% tells the client to activate socket
+set_active(Pid) ->
+ gen_server:cast(Pid, {set_active}).
+
%%====================================================================
%% Server functions
%%====================================================================
@@ -99,6 +103,10 @@ handle_call(_Request, _From, State) ->
%% {noreply, State, Timeout} |
%% {stop, Reason, State} (terminate/2 is called)
%%--------------------------------------------------------------------
+handle_cast({set_active}, State=#proxy{clientsock=Socket}) ->
+ ts_utils:inet_setopts(tcp, Socket,[{active, once}]),
+ {noreply, State};
+
handle_cast(_Msg, State) ->
{noreply, State}.
@@ -120,7 +120,8 @@ handle_call({accepted, _Tag, ClientSock}, _From, State) ->
case ts_client_proxy_sup:start_child(ClientSock) of
{ok, Pid} ->
?LOGF("New connection from~p~n", [inet:peername(ClientSock)],?INFO),
- ok = gen_tcp:controlling_process(ClientSock, Pid);
+ ok = gen_tcp:controlling_process(ClientSock, Pid),
+ ts_client_proxy:set_active(Pid);
Error ->
?LOGF("Failed to launch new client ~p~n",[Error],?ERR),
gen_tcp:close(ClientSock)
@@ -199,7 +200,7 @@ activate(State=#state{plugin=Plugin})->
undefined ->
Portno=?config(proxy_listen_port),
Opts = lists:append(Plugin:socket_opts(),
- [{reuseaddr, true}, {active, once}]),
+ [{reuseaddr, true}, {active, false}]),
case gen_tcp:listen(Portno, Opts) of
{ok, ServerSock} ->
{ok, State#state

0 comments on commit 839efc2

Please sign in to comment.